diff options
author | Richard Biener <rguenther@suse.de> | 2025-04-28 11:15:53 +0200 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2025-05-05 15:08:11 +0200 |
commit | b36014e10c95d3ada1dcdf4695626af90fba0a99 (patch) | |
tree | 63a25c1e5d7a7975c9ef0c37a3b75fda4e85999f /gcc | |
parent | 37c312486186ed9dc2561b2e341fd81f4f1627ec (diff) | |
download | gcc-b36014e10c95d3ada1dcdf4695626af90fba0a99.zip gcc-b36014e10c95d3ada1dcdf4695626af90fba0a99.tar.gz gcc-b36014e10c95d3ada1dcdf4695626af90fba0a99.tar.bz2 |
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.
(cherry picked from commit 7a16ef443b13fff9537baa533597836c57131262)
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/pr119973.c | 39 | ||||
-rw-r--r-- | 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 0000000..a9661a3 --- /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 d9356a8..f79b542 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 |