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.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

Richard.

        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 | 39 +++++++++++++++++++++++++
 gcc/tree-ssa-structalias.cc             | 10 +++----
 2 files changed, 44 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr119973.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr119973.c 
b/gcc/testsuite/gcc.dg/torture/pr119973.c
new file mode 100644
index 00000000000..a9661a3111a
--- /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 d9356a82ad1..f79b54284c6 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
-- 
2.43.0

Reply via email to