]> gcc.gnu.org Git - gcc.git/commitdiff
tree-optimization/111123 - indirect clobbers thrown away too early
authorRichard Biener <rguenther@suse.de>
Thu, 24 Aug 2023 07:32:54 +0000 (09:32 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 24 Aug 2023 13:10:28 +0000 (15:10 +0200)
The testcase in the PR shows that late uninit diagnostic relies
on indirect clobbers in CTORs but we throw those away in the fab
pass which is too early.  The reasoning was they were supposed
to keep SSA names live but that's no longer the case since DCE
doesn't treat them as keeping SSA uses live.

The following instead removes them before out-of-SSA coalescing
which is the thing that's still affected by them.

PR tree-optimization/111123
* tree-ssa-ccp.cc (pass_fold_builtins::execute): Do not
remove indirect clobbers here ...
* tree-outof-ssa.cc (rewrite_out_of_ssa): ... but here.
(remove_indirect_clobbers): New function.

* g++.dg/warn/Wuninitialized-pr111123-1.C: New testcase.

gcc/testsuite/g++.dg/warn/Wuninitialized-pr111123-1.C [new file with mode: 0644]
gcc/tree-outof-ssa.cc
gcc/tree-ssa-ccp.cc

diff --git a/gcc/testsuite/g++.dg/warn/Wuninitialized-pr111123-1.C b/gcc/testsuite/g++.dg/warn/Wuninitialized-pr111123-1.C
new file mode 100644 (file)
index 0000000..17a6f2b
--- /dev/null
@@ -0,0 +1,20 @@
+// { dg-do compile }
+// { dg-require-effective-target c++11 }
+// { dg-options "-O -Wuninitialized" }
+
+#include <vector>
+
+struct Camera {
+    struct P2d {
+            float x, y;
+    };
+    std::vector<P2d> clip_area;
+    float border = 10.f;
+    [[gnu::noinline]] Camera() : clip_area({{border,border}}) { } // { dg-warning "uninitialized" }
+};
+
+Camera foo()
+{
+  Camera c;
+  return c;
+}
index 0bf57a4bbc59f2744631f2ab5be136c591f344f3..767623ab8eac65908c49975b3cb0149f23c5511c 100644 (file)
@@ -1283,6 +1283,33 @@ insert_backedge_copies (void)
     }
 }
 
+/* Remove indirect clobbers.  */
+
+static void
+remove_indirect_clobbers (void)
+{
+  basic_block bb;
+
+  FOR_EACH_BB_FN (bb, cfun)
+    for (auto gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
+      {
+       gimple *stmt = gsi_stmt (gsi);
+       if (gimple_clobber_p (stmt))
+         {
+           tree lhs = gimple_assign_lhs (stmt);
+           if (TREE_CODE (lhs) == MEM_REF
+               && TREE_CODE (TREE_OPERAND (lhs, 0)) == SSA_NAME)
+             {
+               unlink_stmt_vdef (stmt);
+               gsi_remove (&gsi, true);
+               release_defs (stmt);
+               continue;
+             }
+         }
+       gsi_next (&gsi);
+      }
+}
+
 /* Free all memory associated with going out of SSA form.  SA is
    the outof-SSA info object.  */
 
@@ -1305,6 +1332,10 @@ finish_out_of_ssa (struct ssaexpand *sa)
 unsigned int
 rewrite_out_of_ssa (struct ssaexpand *sa)
 {
+  /* Remove remaining indirect clobbers as we do not need those anymore.
+     Those might extend SSA lifetime and restrict coalescing.  */
+  remove_indirect_clobbers ();
+
   /* If elimination of a PHI requires inserting a copy on a backedge,
      then we will have to split the backedge which has numerous
      undesirable performance effects.
@@ -1313,7 +1344,6 @@ rewrite_out_of_ssa (struct ssaexpand *sa)
      copies into the loop itself.  */
   insert_backedge_copies ();
 
-
   /* Eliminate PHIs which are of no use, such as virtual or dead phis.  */
   eliminate_useless_phis ();
 
index 15e65f1600846cd5a22d17e9141bcfab7591c0ed..e048675577fbc70f9c2798a1528d647b68df4db8 100644 (file)
@@ -4302,22 +4302,7 @@ pass_fold_builtins::execute (function *fun)
 
           if (gimple_code (stmt) != GIMPLE_CALL)
            {
-             /* Remove all *ssaname_N ={v} {CLOBBER}; stmts,
-                after the last GIMPLE DSE they aren't needed and might
-                unnecessarily keep the SSA_NAMEs live.  */
-             if (gimple_clobber_p (stmt))
-               {
-                 tree lhs = gimple_assign_lhs (stmt);
-                 if (TREE_CODE (lhs) == MEM_REF
-                     && TREE_CODE (TREE_OPERAND (lhs, 0)) == SSA_NAME)
-                   {
-                     unlink_stmt_vdef (stmt);
-                     gsi_remove (&i, true);
-                     release_defs (stmt);
-                     continue;
-                   }
-               }
-             else if (gimple_assign_load_p (stmt) && gimple_store_p (stmt))
+             if (gimple_assign_load_p (stmt) && gimple_store_p (stmt))
                optimize_memcpy (&i, gimple_assign_lhs (stmt),
                                 gimple_assign_rhs1 (stmt), NULL_TREE);
              gsi_next (&i);
This page took 0.08061 seconds and 5 git commands to generate.