From: Martin Jambor Date: Mon, 30 May 2022 20:04:21 +0000 (+0200) Subject: ipa: Check cst type when propagating controled uses info X-Git-Tag: releases/gcc-12.2.0~260 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=081c472589329fc6c58c4dfed70f1fbc029083a5;p=thirdparty%2Fgcc.git ipa: Check cst type when propagating controled uses info PR 105639 shows that code with type-mismatches can trigger an assert after runnning into a branch that was inteded only for references to variables - as opposed to references to functions. Fixed by moving the condition from the assert to the guarding if statement. gcc/ChangeLog: 2022-05-25 Martin Jambor PR ipa/105639 * ipa-prop.cc (propagate_controlled_uses): Check type of the constant before adding a LOAD reference. gcc/testsuite/ChangeLog: 2022-05-25 Martin Jambor PR ipa/105639 * gcc.dg/ipa/pr105639.c: New test. (cherry picked from commit f571596f8cd8fbad34305b4bec1a813620e0cbf0) --- diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index 0e5966332eb3..7c7bba0c770a 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -4187,14 +4187,13 @@ propagate_controlled_uses (struct cgraph_edge *cs) { int d = ipa_get_controlled_uses (old_root_info, i); int c = rdesc->refcount; + tree cst = ipa_get_jf_constant (jf); rdesc->refcount = combine_controlled_uses_counters (c, d); if (rdesc->refcount != IPA_UNDESCRIBED_USE - && ipa_get_param_load_dereferenced (old_root_info, i)) + && ipa_get_param_load_dereferenced (old_root_info, i) + && TREE_CODE (cst) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND (cst, 0)) == VAR_DECL) { - tree cst = ipa_get_jf_constant (jf); - gcc_checking_assert (TREE_CODE (cst) == ADDR_EXPR - && (TREE_CODE (TREE_OPERAND (cst, 0)) - == VAR_DECL)); symtab_node *n = symtab_node::get (TREE_OPERAND (cst, 0)); new_root->create_reference (n, IPA_REF_LOAD, NULL); if (dump_file) @@ -4204,7 +4203,6 @@ propagate_controlled_uses (struct cgraph_edge *cs) } if (rdesc->refcount == 0) { - tree cst = ipa_get_jf_constant (jf); gcc_checking_assert (TREE_CODE (cst) == ADDR_EXPR && ((TREE_CODE (TREE_OPERAND (cst, 0)) == FUNCTION_DECL) diff --git a/gcc/testsuite/gcc.dg/ipa/pr105639.c b/gcc/testsuite/gcc.dg/ipa/pr105639.c new file mode 100644 index 000000000000..5534fe93fbf4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr105639.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O -w" } */ + +void typedef (*cb) (void); + +static void +bar (cb *fp) +{ + (*fp) (); +} + +void +foo (void) +{ + bar (foo); +}