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

Andrey Chernov ache at freebsd.org
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
./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/
_______________________________________________
freebsd-current at freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscribe at freebsd.org"


More information about the freebsd-bugs mailing list