Bug 174728

Summary: Simple test case that compiles wrong with gcc -O3
Product: [Fedora] Fedora Reporter: Jonathan Kamens <jik>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: rawhide   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-12-06 16:51:47 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
test case none

Description Jonathan Kamens 2005-12-01 19:03:57 UTC
The attached program yields the expected results when compiled 
with "gcc", "gcc -O", and "gcc -O2":

jik2:/tmp!568$ gcc -O2 test.c
jik2:/tmp!569$ ./a.out
format=Foo %s bar, first arg=baz

However, it yields different results when compiled with "gcc -O3":

jik2:/tmp!570$ gcc -O3 test.c
test.c: In function øformat1ù:
test.c:32: warning: passing argument 3 of ødoprntù makes pointer from integer 
w\
ithout a cast
test.c:32: warning: passing argument 6 of ødoprntù from incompatible pointer 
ty\
pe
test.c: In function ømainù:
test.c:37: warning: passing argument 1 of øformat1ù makes integer from pointer 
\
without a cast
test.c:32: warning: passing argument 3 of ødoprntù makes pointer from integer 
w\
ithout a cast
test.c:32: warning: passing argument 6 of ødoprntù from incompatible pointer 
ty\
pe
jik2:/tmp!571$ ./a.out
format=Foo %s bar, first arg=

I believe this is causing a coredump in Emacs, about which I shall soon file a 
second bug report.

gcc-4.0.2-6, emacs-21.4-10.

Comment 1 Jakub Jelinek 2005-12-02 09:17:57 UTC
No testcase has been attached...

Comment 2 Jonathan Kamens 2005-12-02 14:07:24 UTC
Created attachment 121752 [details]
test case

Sorry, here it is.  Incidentally, this is still an issue, but I'm wrong about
it being the cause of the emacs coredump.  That's actually being caused by
-fstack-protector.

Comment 3 Jakub Jelinek 2005-12-06 16:51:47 UTC
The testcase is not valid C and is relying on undefined behaviour.
You get the result you are expecting at -O2 by pure luck.