]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ipa/119973 - IPA PTA issue with global initializers
authorRichard Biener <rguenther@suse.de>
Mon, 28 Apr 2025 09:15:53 +0000 (11:15 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 28 Apr 2025 13:19:50 +0000 (15:19 +0200)
For global initializers with IPA PTA we initialize them from the
IPA reference data but that lacks references to the constant pool.
The following conservatively considers the whole initializer.

PR ipa/119973
* tree-ssa-structalias.cc (create_variable_info_for):
Build constraints from DECL_INITIAL directly rather than
the IPA reference list which is incomplete.

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

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

diff --git a/gcc/testsuite/gcc.dg/torture/pr119973.c b/gcc/testsuite/gcc.dg/torture/pr119973.c
new file mode 100644 (file)
index 0000000..a9661a3
--- /dev/null
@@ -0,0 +1,39 @@
+/* { dg-do run } */
+/* { dg-additional-options "-fipa-pta" } */
+
+static int
+is_valid_domain_name (const char *string)
+{
+  const char *s;
+
+  for (s=string; *s; s++)
+    if (*s == '.')
+      {
+        if (string == s)
+          return 0;
+      }
+
+  return !!*string;
+}
+
+int
+main (void)
+{
+  static struct
+  {
+    const char *name;
+    int valid;
+  } testtbl[] =
+    {
+      { ".", 0 },
+      { nullptr, 0 }
+    };
+  int idx;
+
+  for (idx=0; testtbl[idx].name; idx++)
+    {
+      if (is_valid_domain_name (testtbl[idx].name) != testtbl[idx].valid)
+        __builtin_abort ();
+    }
+  return 0;
+}
index d9356a82ad12a188372c4bbd3bee2f4af500e5bc..f79b54284c64a7bcf8817bbb14fb968384d0650a 100644 (file)
@@ -6529,18 +6529,18 @@ create_variable_info_for (tree decl, const char *name, bool add_id)
          if (!vnode->all_refs_explicit_p ())
            make_copy_constraint (vi, nonlocal_id);
 
-         /* If this is a global variable with an initializer and we are in
-            IPA mode generate constraints for it.  */
-         ipa_ref *ref;
-         for (unsigned idx = 0; vnode->iterate_reference (idx, ref); ++idx)
+         /* While we can in theory walk references for the varpool
+            node that does not cover zero-initialization or references
+            to the constant pool.  */
+         if (DECL_INITIAL (decl))
            {
              auto_vec<ce_s> rhsc;
              struct constraint_expr lhs, *rhsp;
              unsigned i;
-             get_constraint_for_address_of (ref->referred->decl, &rhsc);
              lhs.var = vi->id;
              lhs.offset = 0;
              lhs.type = SCALAR;
+             get_constraint_for (DECL_INITIAL (decl), &rhsc);
              FOR_EACH_VEC_ELT (rhsc, i, rhsp)
                process_constraint (new_constraint (lhs, *rhsp));
              /* If this is a variable that escapes from the unit