Bug 41953

Summary: missing uninitialized warning (SRA,VOP)
Product: gcc Reporter: davidxl <xinliangli>
Component: middle-endAssignee: Richard Biener <rguenth>
Status: ASSIGNED ---    
Severity: enhancement CC: dimhen, gcc-bugs, manu, xinliangli
Priority: P3 Keywords: diagnostic
Version: 4.5.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2009-11-06 10:02:19
Bug Depends on:    
Bug Blocks: 24639    

Description davidxl 2009-11-05 18:23:23 UTC
Compiling the following program with gcc 4.4, correct warning is emitted, but not 4.5. This is related to PR41952.

(Option -fno-tree-sra is needed to trigger the problem).

struct ExtentsBase {
  int startx_;
  int endx_;

int f(const ExtentsBase &e1, int n) {
 ExtentsBase my_extents;
 if (n)
   my_extents.startx_ = e1.startx_;           // Warning missing from 4.5
 return my_extents.startx_;
Comment 1 Andrew Pinski 2009-11-05 23:39:47 UTC
Well in 4.5, there is only MEM for VOPs so I think this comes down to walking the VOP def trees and such.
Comment 2 Richard Biener 2009-11-06 10:02:19 UTC
Yes, the original implementation for uninitialized memory use was very
limited.  Now it's even more limited.
Comment 3 Richard Biener 2017-03-02 10:48:03 UTC
With an even more slightly enhanced patch for PR79345 we can warn here even with -fno-tree-sra, but at -O2 we run into the issue that PRE inserts loads w/o location (and the patch doesn't warn for loads that do not have a location...).
Comment 4 Richard Biener 2017-05-02 07:27:25 UTC
Sth like the following.  Note that fentry_reached just means that there
exists a path from function entry to the use that has the use not
initialized -- it doesn't mean this path can be ever executed (there's
no predicate analysis done to disprove the obvious cases).  With restricting
it to uses that are not predicated the amount of false positives should be
minimal (well, hopefully - eventually we need to restrict this to -O1+
for this reason).  Or finally re-write uninit predicate analysis.

Index: gcc/tree-ssa-uninit.c
--- gcc/tree-ssa-uninit.c       (revision 247368)
+++ gcc/tree-ssa-uninit.c       (working copy)
@@ -319,7 +319,8 @@ warn_uninitialized_vars (bool warn_possi
              oracle_cnt += res;
-             if (data.found_may_defs)
+             if (data.found_may_defs
+                 && ! (fentry_reached && always_executed))
              /* Do not warn if it can be initialized outside this function.
                 If we did not reach function entry then we found killing
@@ -337,7 +338,7 @@ warn_uninitialized_vars (bool warn_possi
              location_t location
                = linemap_resolve_location (line_table, gimple_location (stmt),
                                            LRK_SPELLING_LOCATION, NULL);
-             if (always_executed)
+             if (always_executed && ! data.found_may_defs)
                  if (warning_at (location, OPT_Wuninitialized,
                                  "%qE is used uninitialized in this function",