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

Andrey Chernov ache at
Tue Mar 13 12:46:02 UTC 2007

Copy the segment below to the file a.c
---------------------- cut me here ---------------------
#include <stdio.h>

main() {
printf("%s\n", NULL);
---------------------- cut me here ---------------------
Compile first as
cc a.c
Then compile as
cc -O a.c
got core dump.
Lets see assembler output from
cc -O -S a.c
	.file	"a.c"
	.p2align 2,,3
.globl main
	.type	main, @function
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	andl	$-16, %esp
	subl	$28, %esp
	pushl	$0
	call	puts
	.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?

freebsd-current at mailing list
To unsubscribe, send any mail to "freebsd-current-unsubscribe at"

More information about the freebsd-bugs mailing list