Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Mar 2007 15:11:07 +0300
From:      Andrey Chernov <ache@freebsd.org>
To:        current@freebsd.org
Subject:   Bad gcc -O optimization cause core dump. What to do?
Message-ID:  <20070313121106.GA96293@nagual.pp.ru>
Resent-Message-ID: <20070313123256.GA96813@nagual.pp.ru>

next in thread | raw e-mail | index | archive | help
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@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070313121106.GA96293>