]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/109139 - fix .DEFERRED_INIT removal
authorRichard Biener <rguenther@suse.de>
Wed, 15 Mar 2023 08:47:18 +0000 (09:47 +0100)
committerRichard Biener <rguenther@suse.de>
Wed, 15 Mar 2023 09:29:27 +0000 (10:29 +0100)
The following make sure to strip MEMs when looking for unused
decls on the LHS of .DEFERRED_INIT.

PR tree-optimization/109139
* tree-ssa-live.cc (remove_unused_locals): Look at the
base address for unused decls on the LHS of .DEFERRED_INIT.

* gcc.dg/torture/pr109139.c: New testcase.

gcc/testsuite/gcc.dg/torture/pr109139.c [new file with mode: 0644]
gcc/tree-ssa-live.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr109139.c b/gcc/testsuite/gcc.dg/torture/pr109139.c
new file mode 100644 (file)
index 0000000..9fa97eb
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-ftrivial-auto-var-init=zero" } */
+
+const int COMPARE_CANDIDATE;
+char ipmi_ek_compare_link_record1_0, ipmi_ek_compare_link_record2_0;
+void ipmi_ek_compare_link()
+{
+  for (; ipmi_ek_compare_link_record1_0;)
+    for (; ipmi_ek_compare_link_record2_0;) {
+       int link[COMPARE_CANDIDATE];
+    }
+}
index 9118e82b4f1bf9fcf356349c078ab53dcfe55f49..1be92956cc5476c9120b38e9b520d19c90ee9405 100644 (file)
@@ -897,7 +897,8 @@ remove_unused_locals (void)
            else if (gimple_call_internal_p (stmt, IFN_DEFERRED_INIT))
              {
                tree lhs = gimple_call_lhs (stmt);
-               if (DECL_P (lhs) && !is_used_p (lhs))
+               tree base = get_base_address (lhs);
+               if (DECL_P (base) && !is_used_p (base))
                  {
                    unlink_stmt_vdef (stmt);
                    gsi_remove (&gsi, true);