https://gcc.gnu.org/g:7a16ef443b13fff9537baa533597836c57131262

commit r16-193-g7a16ef443b13fff9537baa533597836c57131262
Author: Richard Biener <rguent...@suse.de>
Date:   Mon Apr 28 11:15:53 2025 +0200

    ipa/119973 - IPA PTA issue with global initializers
    
    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.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr119973.c | 39 +++++++++++++++++++++++++++++++++
 gcc/tree-ssa-structalias.cc             | 10 ++++-----
 2 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr119973.c 
b/gcc/testsuite/gcc.dg/torture/pr119973.c
new file mode 100644
index 000000000000..a9661a3111ae
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr119973.c
@@ -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;
+}
diff --git a/gcc/tree-ssa-structalias.cc b/gcc/tree-ssa-structalias.cc
index d9356a82ad12..f79b54284c64 100644
--- a/gcc/tree-ssa-structalias.cc
+++ b/gcc/tree-ssa-structalias.cc
@@ -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

Reply via email to