Current CVS mainline G++ (3.5.0 20040617) generate warning with command line: g++ -O -Wuninitialized -funit-at-a-time -o test.o -c test.cc but not generate with: g++ -O -Wuninitialized -o test.o -c test.cc for code: --8X----------------------- #include<fstream> int main() { try{ std::ofstream out("test.log"); if(out.fail()) return 1; }catch(...){ return 1; }; return 0; } ---X8----------------------
Created attachment 6547 [details] source code .cc file
Created attachment 6548 [details] preprocessed source code .ii file
Warning text for testcase: test.cc: In function `int main()': test.cc:9: warning: 'T.722' may be used uninitialized in this function
Confirmed. Someone should try to generate a reduced testcase. W.
Note -funit-at-a-time just caused more inlining so ..., there is another bug like this one too. This is all exception related.
Here is a small testcase, having a lot to do with virtual inheritance: ------------------ struct VB { int i; VB(); virtual ~VB(); }; struct D : virtual VB { bool fail() { return (i & 3) != 0; } }; int main() { try { D d; if(d.fail()) return 1; } catch(...) {}; return 0; } --------------------- g/x> /home/bangerth/bin/gcc-3.5-pre/bin/c++ -c -O2 -Wuninitialized -c x.cc x.cc: In function `int main()': x.cc:16: warning: 'T.46' may be used uninitialized in this function This warning is a mainline regression. W.
*** Bug 14564 has been marked as a duplicate of this bug. ***
Richard you said you will deal with PR 14564, the testcase here shows excatly the same problem, it comes from the fact that the uninitialized warnings do not take into account abornal edges in the CFG.
We can't "just ignore" abnormal edges, as that would fail to identify places where variables are *never* assigned. There does, however, appear to be some pessimization going on because of the abnormal edge. The generated code is correct, in case anyone's wondering. The value is only uninitialized along a path that it won't be used.
Subject: Bug 16036 CVSROOT: /cvs/gcc Module name: gcc Changes by: rth@gcc.gnu.org 2004-06-19 05:39:15 Modified files: gcc : ChangeLog gimple-low.c gimplify.c tree-cfg.c Log message: PR c++/16036 * gimple-low.c (lower_function_body): Generate return statement for fall off the end of the function here ... * tree-cfg.c (make_edges): ... instead of here. * gimplify.c (gimplify_return_expr): Mark return temp TREE_NO_WARNING. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.4038&r2=2.4039 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gimple-low.c.diff?cvsroot=gcc&r1=2.4&r2=2.5 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gimplify.c.diff?cvsroot=gcc&r1=2.17&r2=2.18 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-cfg.c.diff?cvsroot=gcc&r1=2.14&r2=2.15
Fixed.