https://gcc.gnu.org/g:0b2b739ca5bbdc9342b4c67d3de816f456877926
commit 0b2b739ca5bbdc9342b4c67d3de816f456877926 Author: Alexandre Oliva <ol...@adacore.com> Date: Tue Jul 16 05:33:07 2024 -0300 [strub] adjust all at-calls type variants at once TYPE_ARG_TYPES of type variants must compare equal, according to verify_type, but adjust_at_calls_type didn't preserve this invariant. Adjust the main type variant and propagate TYPE_ARG_TYPES to all variants. While at that, also adjust the canonical type and its variants, and then verify_type. for gcc/ChangeLog PR c/115848 * ipa-strub.cc (pass_ipa_strub::adjust_at_calls_type_main): Rename from... (pass_ipa_strub::adjust_at_calls_type): ... this. Preserve TYPE_ARG_TYPES across all variants. Adjust TYPE_CANONICAL and verify_type. for gcc/testsuite/ChangeLog PR c/115848 * c-c++-common/strub-pr115848.c: New. Diff: --- gcc/ipa-strub.cc | 41 +++++++++++++++++++++++++++-- gcc/testsuite/c-c++-common/strub-pr115848.c | 6 +++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/gcc/ipa-strub.cc b/gcc/ipa-strub.cc index 8fa7bdf53002..15d91c994bf8 100644 --- a/gcc/ipa-strub.cc +++ b/gcc/ipa-strub.cc @@ -1891,6 +1891,7 @@ public: #undef DEF_IDENT + static inline int adjust_at_calls_type_main (tree); static inline int adjust_at_calls_type (tree); static inline void adjust_at_calls_call (cgraph_edge *, int, tree); static inline void adjust_at_calls_calls (cgraph_node *); @@ -2348,15 +2349,51 @@ strub_watermark_parm (tree fndecl) gcc_unreachable (); } +/* Adjust a STRUB_AT_CALLS function TYPE and all its variants, + preserving TYPE_ARG_TYPES identity, adding a watermark pointer if + it hasn't been added yet. Return the named argument count. */ + +int +pass_ipa_strub::adjust_at_calls_type (tree type) +{ + gcc_checking_assert (same_strub_mode_in_variants_p (type)); + + tree tmain = TYPE_MAIN_VARIANT (type); + tree orig_types = TYPE_ARG_TYPES (tmain); + gcc_checking_assert (TYPE_ARG_TYPES (type) == orig_types); + int named_args = adjust_at_calls_type_main (tmain); + tree mod_types = TYPE_ARG_TYPES (tmain); + + if (mod_types != orig_types) + for (tree other = TYPE_NEXT_VARIANT (tmain); + other != NULL_TREE; other = TYPE_NEXT_VARIANT (other)) + { + gcc_checking_assert (TYPE_ARG_TYPES (other) == orig_types); + TYPE_ARG_TYPES (other) = mod_types; + } + + if (TYPE_CANONICAL (type) + && TYPE_MAIN_VARIANT (TYPE_CANONICAL (type)) != tmain) + { + int ret = adjust_at_calls_type (TYPE_CANONICAL (type)); + gcc_checking_assert (named_args == ret); + } + + if (flag_checking) + verify_type (type); + + return named_args; +} + /* Adjust a STRUB_AT_CALLS function TYPE, adding a watermark pointer if it hasn't been added yet. Return the named argument count. */ int -pass_ipa_strub::adjust_at_calls_type (tree type) +pass_ipa_strub::adjust_at_calls_type_main (tree type) { int named_args = 0; - gcc_checking_assert (same_strub_mode_in_variants_p (type)); + gcc_checking_assert (TYPE_MAIN_VARIANT (type) == type); if (!TYPE_ARG_TYPES (type)) return named_args; diff --git a/gcc/testsuite/c-c++-common/strub-pr115848.c b/gcc/testsuite/c-c++-common/strub-pr115848.c new file mode 100644 index 000000000000..6c8618dad88a --- /dev/null +++ b/gcc/testsuite/c-c++-common/strub-pr115848.c @@ -0,0 +1,6 @@ +/* { dg-do link } */ +/* { dg-options "-flto -r" } */ + +typedef void __attribute__((__strub__)) a(int, int); +a(b); +void c() { b(0, 0); }