Re: Bad gcc -O optimization cause core dump. What to do?

From: Ricardo Nabinger Sanchez <rnsanchez_at_wait4.org>
Date: Tue, 13 Mar 2007 10:13:12 -0300
On Tue, 13 Mar 2007 15:11:07 +0300
Andrey Chernov <ache_at_freebsd.org> wrote:

> cc -O -S a.c
> 	.file	"a.c"
> 	.text
> 	.p2align 2,,3
> .globl main
> 	.type	main, _at_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"

Confirmed on FreeBSD-6.1 RELEASE:

        .file   "bla.c"
        .text
        .p2align 2,,3
.globl main
        .type   main, _at_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.4 [FreeBSD] 20050518"

> 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?

Given that this is not what the user asked (replacing printf with puts), I
consider this a bug.  GCC made its assumption, and it was incorrect--it's not
user's fault.

-- 
Ricardo Nabinger Sanchez     <rnsanchez_at_{gmail.com,wait4.org}>
Powered by FreeBSD

  "Left to themselves, things tend to go from bad to worse."
Received on Tue Mar 13 2007 - 12:38:38 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:06 UTC