From patchwork Tue Aug 31 18:08:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 63309 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 673F0B7126 for ; Wed, 1 Sep 2010 04:08:38 +1000 (EST) Received: (qmail 11436 invoked by alias); 31 Aug 2010 18:08:37 -0000 Received: (qmail 11428 invoked by uid 22791); 31 Aug 2010 18:08:36 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, TW_CC, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.35) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 31 Aug 2010 18:08:32 +0000 Received: from kpbe16.cbf.corp.google.com (kpbe16.cbf.corp.google.com [172.25.105.80]) by smtp-out.google.com with ESMTP id o7VI8TJq022413 for ; Tue, 31 Aug 2010 11:08:29 -0700 Received: from pxi3 (pxi3.prod.google.com [10.243.27.3]) by kpbe16.cbf.corp.google.com with ESMTP id o7VI7M1T004503 for ; Tue, 31 Aug 2010 11:08:28 -0700 Received: by pxi3 with SMTP id 3so3043924pxi.21 for ; Tue, 31 Aug 2010 11:08:28 -0700 (PDT) Received: by 10.114.36.4 with SMTP id j4mr7406187waj.176.1283278107238; Tue, 31 Aug 2010 11:08:27 -0700 (PDT) Received: from coign.google.com (dhcp-172-22-124-178.mtv.corp.google.com [172.22.124.178]) by mx.google.com with ESMTPS id c24sm16848344wam.19.2010.08.31.11.08.25 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 31 Aug 2010 11:08:25 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: [gccgo] Better panic messages for send/receive on nil channel Date: Tue, 31 Aug 2010 11:08:23 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Right now a send or receive on a nil channel will give a panic due to a segmentation violation. This patch adds checks for the condition and gives a more relevant panic message. Committed to gccgo branch. Ian diff -r 6cb25c0c5893 libgo/runtime/go-rec-big.c --- a/libgo/runtime/go-rec-big.c Tue Aug 31 10:07:49 2010 -0700 +++ b/libgo/runtime/go-rec-big.c Tue Aug 31 11:06:24 2010 -0700 @@ -6,6 +6,7 @@ #include +#include "go-panic.h" #include "channel.h" void @@ -14,6 +15,9 @@ size_t alloc_size; size_t offset; + if (channel == NULL) + __go_panic_msg ("receive from nil channel"); + alloc_size = ((channel->element_size + sizeof (uint64_t) - 1) / sizeof (uint64_t)); diff -r 6cb25c0c5893 libgo/runtime/go-rec-small.c --- a/libgo/runtime/go-rec-small.c Tue Aug 31 10:07:49 2010 -0700 +++ b/libgo/runtime/go-rec-small.c Tue Aug 31 11:06:24 2010 -0700 @@ -273,6 +273,9 @@ { uint64_t ret; + if (channel == NULL) + __go_panic_msg ("receive from nil channel"); + __go_assert (channel->element_size <= sizeof (uint64_t)); if (!__go_receive_acquire (channel, for_select)) diff -r 6cb25c0c5893 libgo/runtime/go-send-big.c --- a/libgo/runtime/go-send-big.c Tue Aug 31 10:07:49 2010 -0700 +++ b/libgo/runtime/go-send-big.c Tue Aug 31 11:06:24 2010 -0700 @@ -6,6 +6,7 @@ #include +#include "go-panic.h" #include "channel.h" void @@ -14,6 +15,9 @@ size_t alloc_size; size_t offset; + if (channel == NULL) + __go_panic_msg ("send to nil channel"); + alloc_size = ((channel->element_size + sizeof (uint64_t) - 1) / sizeof (uint64_t)); diff -r 6cb25c0c5893 libgo/runtime/go-send-small.c --- a/libgo/runtime/go-send-small.c Tue Aug 31 10:07:49 2010 -0700 +++ b/libgo/runtime/go-send-small.c Tue Aug 31 11:06:24 2010 -0700 @@ -151,6 +151,9 @@ void __go_send_small (struct __go_channel *channel, uint64_t val, _Bool for_select) { + if (channel == NULL) + __go_panic_msg ("send to nil channel"); + __go_assert (channel->element_size <= sizeof (uint64_t)); if (!__go_send_acquire (channel, for_select))