Bug 850712

Summary: -Wuninitialized/-Wmaybe-uninitialized depends on optimization level
Product: [Fedora] Fedora Reporter: Milan Crha <mcrha>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 17CC: jakub, law
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-08-22 08:45:33 UTC Type: Bug
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
test2.c none

Description Milan Crha 2012-08-22 08:11:12 UTC
Created attachment 606160 [details]
test2.c

Warning about used unitialized variables depends on optimization level. The attached is a test program, which demonstrates the issue. It would be nice to not depend on optimization level here, at least in this case.

This is with gcc-4.7.0-5.fc17.x86_64, and the output based on compilation is here:


$ gcc -g -O0 -Wall -Wextra test2.c -o test2 && ./test2
x:1 p:2
x:0 p:3

$ gcc -g -O2 -Wall -Wextra test2.c -o test2 && ./test2
test2.c: In function ‘main’:
test2.c:14:3: warning: ‘p’ is used uninitialized in this function [-Wuninitialized]
test2.c:7:6: note: ‘p’ was declared here
x:1 p:2
x:0 p:1

Comment 1 Jakub Jelinek 2012-08-22 08:45:33 UTC
That is not a bug.  Warnings that aren't reported by the frontends, but that require some optimizations for it to be performed, obviously do depend on the optimization level.

Comment 2 Milan Crha 2012-08-22 10:56:53 UTC
I do not understand. If you check the code, then there is no compiler optimization required to trigger the use of uninitialized variable.

Comment 3 Jakub Jelinek 2012-08-22 11:57:29 UTC
The uninitialized use is (without inlining/cloning) only conditional, of the may be used uninitialized kind, and for -O0 those are never enabled, because not enough optimizations were performed to remove most of the false positives.