From owner-freebsd-bugs@FreeBSD.ORG Tue Mar 13 13:05:34 2007 Return-Path: X-Original-To: bugs@freebsd.org Delivered-To: freebsd-bugs@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 10D0816A402; Tue, 13 Mar 2007 13:05:34 +0000 (UTC) (envelope-from bde@zeta.org.au) Received: from mailout1.pacific.net.au (mailout1-3.pacific.net.au [61.8.2.210]) by mx1.freebsd.org (Postfix) with ESMTP id CA8DE13C455; Tue, 13 Mar 2007 13:05:33 +0000 (UTC) (envelope-from bde@zeta.org.au) Received: from mailproxy1.pacific.net.au (mailproxy1.pacific.net.au [61.8.2.162]) by mailout1.pacific.net.au (Postfix) with ESMTP id 62D025A042E; Wed, 14 Mar 2007 00:05:32 +1100 (EST) Received: from katana.zip.com.au (katana.zip.com.au [61.8.7.246]) by mailproxy1.pacific.net.au (Postfix) with ESMTP id 62C978C05; Wed, 14 Mar 2007 00:05:31 +1100 (EST) Date: Wed, 14 Mar 2007 00:05:29 +1100 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: Andrey Chernov In-Reply-To: <20070313121106.GA96293@nagual.pp.ru> Message-ID: <20070314000017.Y52372@delplex.bde.org> References: <20070313121106.GA96293@nagual.pp.ru> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: bugs@freebsd.org, ache@nagual.pp.ru, current@freebsd.org Subject: Re: Bad gcc -O optimization cause core dump. What to do? X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Mar 2007 13:05:34 -0000 On Tue, 13 Mar 2007, Andrey Chernov wrote: > Copy the segment below to the file a.c > ---------------------- cut me here --------------------- > #include > > main() { > printf("%s\n", NULL); > } > ---------------------- cut me here --------------------- > It calls "puts(NULL)" with core dump. > It means "printf("%s\n", NULL)" is overoptimized. > BTW, things like "printf("1%s\n", NULL)" are not overoptimized. > Any ideas? Is it right or needs to be fixed? This happens with gcc-3.4.6 and 4.2 but not with 3.3.3. It also happens if NULL is replaced by a variable containing a null pointer. The case of a literal NULL should probably be an error at compile time (__nonnull() doesn't apply to printf() but the compiler could detect this error when it optimizes to use puts()). This is not wrong, since the null pointer gives undefined behaviour, but it breaks the normal undefined behaviour of printing "(null)". Bruce