]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/105646 - re-interpret always executed in uninit diag
authorRichard Biener <rguenther@suse.de>
Fri, 19 Aug 2022 13:11:14 +0000 (15:11 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 29 Sep 2022 07:34:00 +0000 (09:34 +0200)
The following fixes PR105646, not diagnosing

int f1();
int f3(){
    auto const & a = f1();
    bool v3{v3};
    return a;
}

with optimization because the early uninit diagnostic pass only
diagnoses always executed cases.  The patch does this by
re-interpreting what always executed means and choosing to
ignore exceptional and abnormal control flow for this.  At the
same time it improves things as suggested in a comment - when
the value-numbering run done without optimizing figures there's
a fallthru path, consider blocks on it as always executed.

PR tree-optimization/105646
* tree-ssa-uninit.cc (warn_uninitialized_vars): Pre-compute
the set of fallthru reachable blocks from function entry
and use that to determine wlims.always_executed.

* g++.dg/uninit-pr105646.C: New testcase.

gcc/testsuite/g++.dg/uninit-pr105646.C [new file with mode: 0644]
gcc/tree-ssa-uninit.cc

diff --git a/gcc/testsuite/g++.dg/uninit-pr105646.C b/gcc/testsuite/g++.dg/uninit-pr105646.C
new file mode 100644 (file)
index 0000000..48ceb98
--- /dev/null
@@ -0,0 +1,17 @@
+// { dg-do compile }
+// { dg-require-effective-target c++11 }
+// { dg-options "-O2 -Wuninitialized" }
+
+int f1();
+int f2(){
+    bool v2{v2}; // { dg-warning "is used uninitialized" }
+    auto const & a = f1();
+    return a;
+}
+int f3(){
+    auto const & a = f1();
+    // Diagnose the following when optimizing and as unconditional
+    // uninitialized use despite f1 possibly throwing
+    bool v3{v3}; // { dg-warning "is used uninitialized" }
+    return a;
+}
index eae29f88f9db83be9ba5e6dfb7c71553b54f9aab..bde23997a0ada2b18403477609c56704ebac4459 100644 (file)
@@ -991,14 +991,20 @@ warn_uninitialized_vars (bool wmaybe_uninit)
   auto_bb_flag ft_reachable (cfun);
 
   /* Mark blocks that are always executed when we ignore provably
-     not executed edges.  */
+     not executed and EH and abnormal edges.  */
   basic_block bb = single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun));
   while (!(bb->flags & ft_reachable))
     {
       bb->flags |= ft_reachable;
+      edge e = find_fallthru_edge (bb->succs);
+      if (e && e->flags & EDGE_EXECUTABLE)
+       {
+         bb = e->dest;
+         continue;
+       }
       /* Find a single executable edge.  */
       edge_iterator ei;
-      edge e, ee = NULL;
+      edge ee = NULL;
       FOR_EACH_EDGE (e, ei, bb->succs)
        if (e->flags & EDGE_EXECUTABLE)
          {