Bug 16036

Summary: [4.0 regression] Spurious "may be used uninitialized in this function" warning
Product: gcc Reporter: wanderer
Component: c++Assignee: Richard Henderson <rth>
Status: RESOLVED FIXED    
Severity: normal CC: falk, gcc-bugs
Priority: P2 Keywords: diagnostic
Version: 4.0.0   
Target Milestone: 4.0.0   
Host: i386-unknown-freebsd5.1 Target: i386-unknown-freebsd5.1
Build: i386-unknown-freebsd5.1 Known to work: 3.4.0
Known to fail: 4.0.0 Last reconfirmed: 2004-06-17 19:54:04
Bug Depends on:    
Bug Blocks: 24639, 14564    
Attachments: source code .cc file
preprocessed source code .ii file

Description wanderer 2004-06-17 18:40:20 UTC
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----------------------
Comment 1 wanderer 2004-06-17 18:41:07 UTC
Created attachment 6547 [details]
source code .cc file
Comment 2 wanderer 2004-06-17 18:41:57 UTC
Created attachment 6548 [details]
preprocessed source code .ii file
Comment 3 wanderer 2004-06-17 18:46:46 UTC
Warning text for testcase:
test.cc: In function `int main()':
test.cc:9: warning: 'T.722' may be used uninitialized in this function
Comment 4 Wolfgang Bangerth 2004-06-17 19:27:17 UTC
Confirmed. Someone should try to generate a reduced testcase. 
W. 
Comment 5 Andrew Pinski 2004-06-17 19:47:10 UTC
Note -funit-at-a-time just caused more inlining so ..., there is another bug like this one too.  This is all 
exception related.
Comment 6 Wolfgang Bangerth 2004-06-17 19:54:04 UTC
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. 
Comment 7 Andrew Pinski 2004-06-17 20:49:54 UTC
*** Bug 14564 has been marked as a duplicate of this bug. ***
Comment 8 Andrew Pinski 2004-06-17 20:51:21 UTC
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.
Comment 9 Richard Henderson 2004-06-18 02:14:57 UTC
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.
Comment 10 CVS Commits 2004-06-19 05:39:20 UTC
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

Comment 11 Richard Henderson 2004-06-19 05:42:27 UTC
Fixed.