https://gcc.gnu.org/g:75a6c764b727a4938c2117129d1ee9aadfb1a0d0
commit r17-6283-g75a6c764b727a4938c2117129d1ee9aadfb1a0d0 Author: Jan Hubicka <[email protected]> Date: Sun Nov 15 08:35:20 2026 +0100 Fix TREE_READONLY check in ipa_find_agg_cst_from_init ipa_find_agg_cst_from_init intended to reject non-constant, non-CONST_DECL objects unless they are TREE_READONLY variables, but there is a typo. gcc/ChangeLog: * ipa-prop.cc (ipa_find_agg_cst_from_init): Require both VAR_P and TREE_READONLY when scalar is neither CONSTANT_CLASS_P nor CONST_DECL. gcc/testsuite/ChangeLog: * gcc.dg/ipa/fnsummary-14.c: New test. Diff: --- gcc/ipa-prop.cc | 2 +- gcc/testsuite/gcc.dg/ipa/fnsummary-14.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index 23fbfd29f2f7..9da18d60742d 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -4489,7 +4489,7 @@ ipa_find_agg_cst_from_init (tree scalar, HOST_WIDE_INT offset, bool by_ref, tree if (!CONSTANT_CLASS_P (scalar) && TREE_CODE (scalar) != CONST_DECL - && !(VAR_P (scalar) || !TREE_READONLY (scalar))) + && !(VAR_P (scalar) && TREE_READONLY (scalar))) return NULL_TREE; poly_offset_int bit_off diff --git a/gcc/testsuite/gcc.dg/ipa/fnsummary-14.c b/gcc/testsuite/gcc.dg/ipa/fnsummary-14.c new file mode 100644 index 000000000000..c7a193979155 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/fnsummary-14.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target label_values } */ +/* { dg-options "-O2 -fno-early-inlining" } */ + +void cold_work (void); + +static int +check (const char *p) +{ + if (p[0] == 0) + cold_work (); + return 0; +} + +int +caller (void) +{ +lbl: + return check ((const char *) &&lbl); +}
