From owner-freebsd-current@FreeBSD.ORG Tue Mar 13 12:11:10 2007 Return-Path: X-Original-To: current@freebsd.org Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 1D43816A401 for ; Tue, 13 Mar 2007 12:11:10 +0000 (UTC) (envelope-from ache@nagual.pp.ru) Received: from nagual.pp.ru (nagual.pp.ru [194.87.13.69]) by mx1.freebsd.org (Postfix) with ESMTP id 924AC13C44B for ; Tue, 13 Mar 2007 12:11:09 +0000 (UTC) (envelope-from ache@nagual.pp.ru) Received: from nagual.pp.ru (ache@localhost [127.0.0.1]) by nagual.pp.ru (8.13.8/8.13.8) with ESMTP id l2DCB8Bl096455 for ; Tue, 13 Mar 2007 15:11:08 +0300 (MSK) (envelope-from ache@nagual.pp.ru) Received: (from ache@localhost) by nagual.pp.ru (8.13.8/8.13.8/Submit) id l2DCB8pN096454 for current@freebsd.org; Tue, 13 Mar 2007 15:11:08 +0300 (MSK) (envelope-from ache) Date: Tue, 13 Mar 2007 15:11:07 +0300 From: Andrey Chernov To: current@freebsd.org Message-ID: <20070313121106.GA96293@nagual.pp.ru> Mail-Followup-To: Andrey Chernov , current@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.14 (2007-02-12) Cc: Subject: Bad gcc -O optimization cause core dump. What to do? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Mar 2007 12:11:10 -0000 Copy the segment below to the file a.c ---------------------- cut me here --------------------- #include main() { printf("%s\n", NULL); } ---------------------- cut me here --------------------- Compile first as cc a.c ./a.out got (null) Then compile as cc -O a.c ./a.out got core dump. Lets see assembler output from cc -O -S a.c .file "a.c" .text .p2align 2,,3 .globl main .type main, @function main: pushl %ebp movl %esp, %ebp subl $8, %esp andl $-16, %esp subl $28, %esp pushl $0 call puts leave ret .size main, .-main .ident "GCC: (GNU) 3.4.6 [FreeBSD] 20060825" 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? -- http://ache.pp.ru/