https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128363
Bug ID: 128363
Summary: ipa-strub: pass_ipa_strub::execute constructs
attr_fnspec from attribute TREE_LIST instead of
STRING_CST at ipa-strub.cc:2935
Product: gcc
Version: 16.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ipa
Assignee: unassigned at gcc dot gnu.org
Reporter: 220245569 at seu dot edu.cn
CC: 220255623 at seu dot edu.cn, jianhao.xu at seu dot edu.cn
Target Milestone: ---
Target: *-*-*
Reproducer
----------
$ cat trigger.c
long __attribute__((strub("internal")))
lround (volatile double x)
{
return (long) x;
}
long call_it (double v)
{
return lround (v) + lround (v);
}
Compile flag: x86_64-linux-gnu-gcc -O2 -fchecking -c trigger.c
during IPA pass: strub
trigger.c:10:1: internal compiler error: invalid fn spec attribute ""
10 | }
| ^
0x24ea9c6 attr_fnspec::verify()
0x2010784 (anonymous namespace)::pass_ipa_strub::execute(function*)
Root cause
----------
In pass_ipa_strub::execute (gcc/ipa-strub.cc:2934-2935), when a STRUB_INTERNAL
function is split and at least one parameter is converted into an indirect
reference (adjust_ftype > 0, e.g. a volatile parameter on a function whose
type carries attribute "fn spec"), the pass checks whether "fn spec" must be
dropped:
bool drop_fnspec = false;
tree fnspec = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (nftype));
attr_fnspec spec = fnspec ? attr_fnspec (fnspec) : attr_fnspec ("");
lookup_attribute returns the attribute TREE_LIST node, whereas
attr_fnspec (const_tree identifier) (gcc/attr-fnspec.h:95-101) expects the
STRING_CST inside TREE_VALUE (TREE_VALUE (fnspec)) (as used at
ipa-strub.cc:2398 and :3004). Passing the TREE_LIST node directly reads
garbage str/len and fails STRING_CST_CHECK / attr_fnspec::verify ().
Suggested Fix
-------------
Unwrap TREE_VALUE (TREE_VALUE (fnspec)) at gcc/ipa-strub.cc:2935, matching
lines 2398 and 3004:
attr_fnspec spec = (fnspec
? attr_fnspec (TREE_VALUE (TREE_VALUE (fnspec)))
: attr_fnspec (""));