Bug 39502

Summary: Unexpected uninitialized warning
Product: gcc Reporter: Alexander Elbs <alex>
Component: adaAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED WONTFIX    
Severity: enhancement CC: alex, ebotcazou, gcc-bugs, kayhayen, manu
Priority: P3    
Version: 4.3.3   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:
Bug Depends on:    
Bug Blocks: 24639    
Attachments: spec file
Body to spec
seperate body with code triggering the warning
Makefile to compile the sample code
Similar code, not sure if same or different bug.

Description Alexander Elbs 2009-03-19 13:44:42 UTC
By compiling the attached files I get a warning like this:
./some_package-some_seperate_package.adb: In function 'SOME_PACKAGE.SOME_SEPERATE_PACKAGE.GET_STATE':
./some_package-some_seperate_package.adb:22: warning: 'state_infos.current_state' is used uninitialized in this function

but I think there should be no warning at all.

It seems it takes several conditions to trigger this warning: 
 - a record variable as a out parameter
 - the code most be in a seperate package
 - The flags -Wuninitialized and -fPIC need to be set

I can reproduce this on 4.3.3 and 4.3.0 (and probably more versions).


$ gcc -v -save-temps -c -I./ -Wuninitialized -fPIC  -O2 ./some_package.adb
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.3-5ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-I./' '-Wuninitialized' '-fPIC' '-O2' '-mtune=generic'
 /usr/lib/gcc/x86_64-linux-gnu/4.3.3/gnat1 -I./ -quiet -dumpbase some_package.adb -O2 -Wuninitialized -fPIC -mtune=generic ./some_package.adb -o some_package.s
./some_package-some_seperate_package.adb: In function 'SOME_PACKAGE.SOME_SEPERATE_PACKAGE.GET_STATE':
./some_package-some_seperate_package.adb:22: warning: 'state_infos.current_state' is used uninitialized in this function
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-I./' '-Wuninitialized' '-fPIC' '-O2' '-mtune=generic'
 as -V -Qy -o some_package.o some_package.s
GNU assembler version 2.19.1 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.19.1
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.3.3/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.3.3/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-I./' '-Wuninitialized' '-fPIC' '-O2' '-mtune=generic'


Regards
Alexander Elbs.
Comment 1 Alexander Elbs 2009-03-19 13:46:14 UTC
Created attachment 17493 [details]
spec file
Comment 2 Alexander Elbs 2009-03-19 13:46:36 UTC
Created attachment 17494 [details]
Body to spec
Comment 3 Alexander Elbs 2009-03-19 13:47:18 UTC
Created attachment 17495 [details]
seperate body with code triggering the warning
Comment 4 Alexander Elbs 2009-03-19 13:47:59 UTC
Created attachment 17496 [details]
Makefile to compile the sample code
Comment 5 Alexander Elbs 2009-03-19 14:02:23 UTC
Created attachment 17497 [details]
Similar code, not sure if same or different bug.

This sample code is closer to our original finding of the bug. Not sure if the first package oversimplified and found another/similar bug.
Comment 6 Kay Hayen 2009-10-08 15:02:37 UTC
Hello,

is there anything else we can do to help with this bug?

Yours,
Kay Hayen
Comment 7 Arnaud Charlet 2009-10-08 15:08:35 UTC
Feel free to submit a patch.
Note that middle-end warnings (such as -Wuninitialized) do not always support
properly all front-end semantics, in particular for high level languages such
as Ada, so I'd recommend simply removing this switch.

Classifying as an enhancement btw, since this is only a warning, and warnings
always produce false positives, so this is not necessarily unexpected.
Comment 8 Manuel López-Ibáñez 2009-10-08 17:39:47 UTC
The output of -fdump-tree-optimized-all-lineno and -fdump-tree-ssa-all-lineno with and without -fPIC would be interesting. Also, GCC 4.4 and 4.5 fixed a lot of false positives in Wuninitialized, so please try with at least GCC 4.4.1.
Comment 9 Eric Botcazou 2010-11-27 19:12:45 UTC
No feedback.