Bug 40146 - Unexplained "'<anonymous>' is used uninitialized in this function" warning
Summary: Unexplained "'<anonymous>' is used uninitialized in this function" warning
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2009-05-14 13:09 UTC by Caolan McNamara
Modified: 2013-11-20 00:59 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
test-case (13.01 KB, text/x-c++src)
2009-05-14 13:09 UTC, Caolan McNamara
Details
smaller test-case (752 bytes, text/plain)
2009-08-27 11:17 UTC, Caolan McNamara
Details
different test case (141 bytes, text/plain)
2009-10-16 11:05 UTC, Andreas Beckmann
Details
pre-processed output of the file that emitted the false positive using the commandline mentioned in my comment (82.88 KB, text/plain)
2010-01-10 23:29 UTC, Matt Hargett
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Caolan McNamara 2009-05-14 13:09:00 UTC
With some code (attached) using an anonymous namespace I get an unexplained "‘<anonymous>’ is used uninitialized in this function" with -Wall, with no indication of what is seen to be used uninitialized. Changing the namespace to a named one removes the error, as does removing part of the body of a used method. 

g++ (GCC) 4.4.0 20090506 (Red Hat 4.4.0-4)

-DTEST1 names the namespace
-DTEST2 comments out the body of the offending method
"wiggling" the code makes it disappear/reappear, but difficult to know what the problem is so as to make the test-case a more reasonable size

$ g++ -O2 -c -Wall foo.cxx
foo.cxx: In function ‘bool demo()’:
foo.cxx:4033: warning: ‘<anonymous>’ is used uninitialized in this function
foo.cxx:4033: note: ‘<anonymous>’ was declared here
$ g++ -DTEST1 -O2 -c -Wall foo.cxx
$ g++ -DTEST2 -O2 -c -Wall foo.cxx

Looks similar to bug #38908 but that one compiles without warnings here
Comment 1 Caolan McNamara 2009-05-14 13:09:32 UTC
Created attachment 17864 [details]
test-case
Comment 2 Andrew Pinski 2009-05-14 14:31:59 UTC
Well with -DTEST1, the functions which were in the anonymous namespace are now in the normal namespace which means they are going to be exported from the TU which changes the inlining decisions.
Comment 3 Wolfgang Bangerth 2009-08-25 13:54:08 UTC
Hm, can you try to come up with a smaller testcase for which it may be a bit
simpler to see what is going on?

Thanks
 W.
Comment 4 Caolan McNamara 2009-08-27 11:17:20 UTC
Created attachment 18436 [details]
smaller test-case

Here's a smaller one, perturbing nearly any line in this makes the warning go away, various sample lines are commented as such in this 100 line example.

Like before...
g++ -DTEST -O2 -c -Wall foo.cxx
no warnings, while
g++ -O2 -c -Wall foo.cxx
foo.cxx: In function 'bool demo()':
foo.cxx:83: warning: '<anonymous>' is used uninitialized in this function
foo.cxx:83: note: '<anonymous>' was declared here
Comment 5 Wolfgang Bangerth 2009-08-27 11:35:06 UTC
The warning isn't triggered any more with current mainline. 

Can someone gives this a try with the current 4.4.x branch?

W.
Comment 6 Shawn Starr 2009-09-10 17:44:25 UTC
I can reproduce this compiling Second Life from trunk

cc1plus: warnings being treated as errors                                                                                                              
/home/spstarr/Downloads/viewer-trunk/indra/llcommon/lldarray.h: In destructor ‘LLFrameStats::~LLFrameStats()’:                                         
/home/spstarr/Downloads/viewer-trunk/indra/llcommon/lldarray.h:60: error: ‘<anonymous>’ is used uninitialized in this function                         
/home/spstarr/Downloads/viewer-trunk/indra/llcommon/lldarray.h:60: note: ‘<anonymous>’ was declared here                                               
make[2]: *** [newview/CMakeFiles/secondlife-bin.dir/llframestats.o] Error 1                                                                            

In this case, the type being passed in is a class.


Given: Where FrameData is a private class inside LLFramestats

LLDynamicArray<FrameData> mFrameData;


Where LLDynamicArray is:


// class LLDynamicArray<>; // = std::vector + reserves <BlockSize> elements

template <typename Type, int BlockSize = 32>
class LLDynamicArray : public std::vector<Type>


Offending code: Method inside template class:

void reset() { std::vector<Type>::resize(0); }  

Type == FrameData.

If you checkout the code from Second Life trunk you will trigger this easily. You will need other patches since they have other GCC 4.4 compile issues (minor that I have fixed locally)

SVN is: http://svn.secondlife.com/svn/linden/trunk/
Comment 7 Andrew Pinski 2009-09-10 18:15:35 UTC
  # VUSE <D.10497_132(D)>
  # aInstCtor_134 = VDEF <aInstCtor_133(D)>
  aInstCtor = D.10497;
  # VUSE <D.10496_135(D)>
  # aDataCtor_137 = VDEF <aDataCtor_136(D)>
  aDataCtor = D.10496;
  # VUSE <m_pInstance_138(D)>
  p_4 = m_pInstance;
Comment 8 Andrew Pinski 2009-09-10 18:18:58 UTC
(In reply to comment #7)
>   # VUSE <D.10497_132(D)>
>   # aInstCtor_134 = VDEF <aInstCtor_133(D)>
>   aInstCtor = D.10497;
>   # VUSE <D.10496_135(D)>
>   # aDataCtor_137 = VDEF <aDataCtor_136(D)>
>   aDataCtor = D.10496;
>   # VUSE <m_pInstance_138(D)>
>   p_4 = m_pInstance;


  struct StaticInstanceWithInit D.10497;

Where StaticInstanceWithInit is an empty class except for a member function .

This should have been fixed by http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38908 but was not.
Comment 9 Andreas Beckmann 2009-10-16 11:05:44 UTC
Created attachment 18809 [details]
different test case

I've seen this spurious warning, too, and could reduce it to a different, much smaller test case.
Comment 10 Andreas Beckmann 2009-10-16 13:11:04 UTC
=== compile command (shows the spurious warning) ===
x86_64-linux-gnu-g++-4.4.x -O2 -W -Wall -DSPURIOUS_WARNING -c anonymous-iuuitf.cpp
=== ===

=== compile command (no spurious warning) ===
x86_64-linux-gnu-g++-4.4.x -O2 -W -Wall -c anonymous-iuuitf.cpp
=== ===

=== spurious warning reported: ===
anonymous-iuuitf.cpp: In function ‘(static initializers for anonymous-iuuitf.cpp)’:
anonymous-iuuitf.cpp:45: warning: ‘<anonymous>’ is used uninitialized in this function
=== ===

The spurious warning also occurs with a i686 4.4.x compiler.
It does not happen with 4.3.x or trunk/4.5.x (both x86_64 and i686).
The warning also disappears if optimization is reduced from -O2 to -O1.

=== verbose output ===
$ x86_64-linux-gnu-g++-4.4.x -v -O2 -W -Wall -DSPURIOUS_WARNING -c anonymous-iuuitf.cpp

Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4_4-branch/configure --prefix=/opt/software/x86_64/gcc-4.4.x --program-suffix=-4.4.x --enable-languages=c,c++ --enable-checking
Thread model: posix
gcc version 4.4.3 20091016 (prerelease) (GCC)
COLLECT_GCC_OPTIONS='-v' '-O2' '-W' '-Wall' '-DSPURIOUS_WARNING' '-c' '-shared-libgcc' '-mtune=generic'
 /opt/software/x86_64/gcc-4.4.x/libexec/gcc/x86_64-unknown-linux-gnu/4.4.3/cc1plus -quiet -v -D_GNU_SOURCE -DSPURIOUS_WARNING anonymous-iuuitf.cpp -quiet -dumpbase anonymous-iuuitf.cpp -mtune=generic -auxbase anonymous-iuuitf -O2 -W -Wall -version -o /tmp/ccrjG8Y8.s
ignoring nonexistent directory "/opt/software/x86_64/gcc-4.4.x/lib/gcc/x86_64-unknown-linux-gnu/4.4.3/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /opt/software/x86_64/gcc-4.4.x/lib/gcc/x86_64-unknown-linux-gnu/4.4.3/../../../../include/c++/4.4.3
 /opt/software/x86_64/gcc-4.4.x/lib/gcc/x86_64-unknown-linux-gnu/4.4.3/../../../../include/c++/4.4.3/x86_64-unknown-linux-gnu
 /opt/software/x86_64/gcc-4.4.x/lib/gcc/x86_64-unknown-linux-gnu/4.4.3/../../../../include/c++/4.4.3/backward
 /usr/local/include
 /opt/software/x86_64/gcc-4.4.x/include
 /opt/software/x86_64/gcc-4.4.x/lib/gcc/x86_64-unknown-linux-gnu/4.4.3/include
 /opt/software/x86_64/gcc-4.4.x/lib/gcc/x86_64-unknown-linux-gnu/4.4.3/include-fixed
 /usr/include
End of search list.
GNU C++ (GCC) version 4.4.3 20091016 (prerelease) (x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.4.3 20091016 (prerelease), GMP version 4.3.1, MPFR version 2.4.1-p2.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 2f5c889faec03641af0e9a45c39b0565
anonymous-iuuitf.cpp: In function ‘(static initializers for anonymous-iuuitf.cpp)’:
anonymous-iuuitf.cpp:45: warning: ‘<anonymous>’ is used uninitialized in this function
COLLECT_GCC_OPTIONS='-v' '-O2' '-W' '-Wall' '-DSPURIOUS_WARNING' '-c' '-shared-libgcc' '-mtune=generic'
 as -V -Qy -o anonymous-iuuitf.o /tmp/ccrjG8Y8.s
GNU assembler version 2.19.91 (x86_64-linux-gnu) using BFD version (GNU Binutils for Debian) 2.19.91.20091006
COMPILER_PATH=/opt/software/x86_64/gcc-4.4.x/libexec/gcc/x86_64-unknown-linux-gnu/4.4.3/:/opt/software/x86_64/gcc-4.4.x/libexec/gcc/x86_64-unknown-linux-gnu/4.4.3/:/opt/software/x86_64/gcc-4.4.x/libexec/gcc/x86_64-unknown-linux-gnu/:/opt/software/x86_64/gcc-4.4.x/lib/gcc/x86_64-unknown-linux-gnu/4.4.3/:/opt/software/x86_64/gcc-4.4.x/lib/gcc/x86_64-unknown-linux-gnu/
LIBRARY_PATH=/opt/software/x86_64/gcc-4.4.x/lib/gcc/x86_64-unknown-linux-gnu/4.4.3/:/opt/software/x86_64/gcc-4.4.x/lib/gcc/x86_64-unknown-linux-gnu/4.4.3/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/opt/software/x86_64/gcc-4.4.x/lib/gcc/x86_64-unknown-linux-gnu/4.4.3/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-O2' '-W' '-Wall' '-DSPURIOUS_WARNING' '-c' '-shared-libgcc' '-mtune=generic'
=== ===
Comment 11 Matt Hargett 2010-01-10 22:01:15 UTC
I get this same problem when compiling scummvm (http://scummvm.org) on Ubuntu 9.10/amd64 using the default GCC 4.4.1:

g++ -O1 -finline-small-functions -finline-functions -Wp,-MMD,"engines/sci/.deps/console.d",-MQ,"engines/sci/console.o",-MP -Wall -Werror -g -ansi -W -Wno-unused-parameter -Wno-empty-body -pedantic -Wno-long-long -Wno-multichar -Wno-unknown-pragmas -Wno-reorder -fno-strict-aliasing  -Wpointer-arith -Wcast-qual -Wcast-align -Wshadow -Wimplicit -Wnon-virtual-dtor -Wwrite-strings -fno-rtti -fno-exceptions -fcheck-new -Wuninitialized -DSCUMMVM_SVN_REVISION=\"47235\" -DHAVE_CONFIG_H -DUNIX -DDATA_PATH=\"/usr/local/share/scummvm\" -DPLUGIN_DIRECTORY=\"/usr/local/lib/scummvm\" -DSDL_BACKEND -DENABLE_SCUMM=STATIC_PLUGIN -DENABLE_SCUMM_7_8 -DENABLE_HE -DENABLE_AGI=STATIC_PLUGIN -DENABLE_AGOS=STATIC_PLUGIN -DENABLE_AGOS2 -DENABLE_CINE=STATIC_PLUGIN -DENABLE_CRUISE=STATIC_PLUGIN -DENABLE_DRACI=STATIC_PLUGIN -DENABLE_DRASCULA=STATIC_PLUGIN -DENABLE_GOB=STATIC_PLUGIN -DENABLE_GROOVIE=STATIC_PLUGIN -DENABLE_GROOVIE2 -DENABLE_KYRA=STATIC_PLUGIN -DENABLE_LOL -DENABLE_LURE=STATIC_PLUGIN -DENABLE_M4=STATIC_PLUGIN -DENABLE_MADE=STATIC_PLUGIN -DENABLE_MOHAWK=STATIC_PLUGIN -DENABLE_PARALLACTION=STATIC_PLUGIN -DENABLE_QUEEN=STATIC_PLUGIN -DENABLE_SAGA=STATIC_PLUGIN -DENABLE_IHNM -DENABLE_SAGA2 -DENABLE_SCI=STATIC_PLUGIN -DENABLE_SCI32 -DENABLE_SKY=STATIC_PLUGIN -DENABLE_SWORD1=STATIC_PLUGIN -DENABLE_SWORD2=STATIC_PLUGIN -DENABLE_TEENAGENT=STATIC_PLUGIN -DENABLE_TINSEL=STATIC_PLUGIN -DENABLE_TOUCHE=STATIC_PLUGIN -DENABLE_TUCKER=STATIC_PLUGIN -I. -I. -I./engines -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -c engines/sci/console.cpp -o engines/sci/console.o
cc1plus: warnings being treated as errors
In file included from ./common/array.h:29,
                 from ./common/fs.h:28,
                 from ./engines/engine.h:30,
                 from ./engines/sci/sci.h:29,
                 from engines/sci/console.cpp:28:
./common/algorithm.h: In function ‘void Common::sort(T, T, StrictWeakOrdering) [with T = Common::ListInternal::Iterator<Sci::ResourceId>, StrictWeakOrdering = Sci::ResourceIdLess]’:
./common/algorithm.h:207: error: ‘<anonymous>’ may be used uninitialized in this function
./common/algorithm.h:207: error: ‘<anonymous>’ may be used uninitialized in this function
./common/algorithm.h:208: error: ‘<anonymous>’ may be used uninitialized in this function
./common/algorithm.h:208: error: ‘<anonymous>’ may be used uninitialized in this function
./common/algorithm.h:207: error: ‘<anonymous>’ may be used uninitialized in this function
./common/algorithm.h:208: error: ‘<anonymous>’ may be used uninitialized in this function


The issue does not occur with gcc-4.3 or gcc-4.5.20091228. I noticed the issue when compiling with -O3, but reduced it to the above commandline. (Something undocumented must happen at -O1, because putting the individual options for -O1 on the commandline  didn't reproduce the issue.)

Pre-processed sources are attached.
Comment 12 Matt Hargett 2010-01-10 23:29:54 UTC
Created attachment 19533 [details]
pre-processed output of the file that emitted the false positive using the commandline mentioned in my comment
Comment 13 Manuel López-Ibáñez 2010-01-11 18:39:03 UTC
If this doesn't occur in GCC 4.5, the best we can do is to put the testcases in the testsuite and close this. Many things changed from 4.4. to 4.5 that may have cause the bug to disappear and that won't be backported, so even looking for them would be a waste of developer's time.
Comment 14 Caolan McNamara 2010-07-13 14:37:03 UTC
Checking with gcc 4.5, this works fine for me now, so I'm happy to call this fixed in 4.5.
Comment 15 Manuel López-Ibáñez 2010-07-13 15:22:38 UTC
Before closing this, please check all testcases provided and add at least one of them to the testsuite.
Comment 16 Jeffrey A. Law 2013-11-20 00:59:52 UTC
Per c#13 and c#14.