https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96040

--- Comment #5 from Martin Jambor <jamborm at gcc dot gnu.org> ---
IPA-split puts the double access to the union in the .part function
and keeps only the long int access in the "original" function.
IPA-SRA thinks it can work with that but the code in "transitive" call
parameter splitting apparently does not handle this case properly.

The easiest fix and probably the one most suitable for backporting is
to prevent splitting of such unions with the following:

--- a/gcc/ipa-sra.c
+++ b/gcc/ipa-sra.c
@@ -3271,7 +3271,9 @@ all_callee_accesses_present_p (isra_param_desc
*param_desc,
        continue;
       param_access *pacc = find_param_access (param_desc, argacc->unit_offset,
                                              argacc->unit_size);
-      if (!pacc || !pacc->certain)
+      if (!pacc
+         || !pacc->certain
+         || !types_compatible_p (argacc->type, pacc->type))
        return false;
     }
   return true;


Alternatively, we can of course handle the type mismatch and insert
appropriate V_C_E:

diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c
index 2cc4bc79dc1..de9bad78712 100644
--- a/gcc/ipa-param-manipulation.c
+++ b/gcc/ipa-param-manipulation.c
@@ -641,6 +641,12 @@ ipa_param_adjustments::modify_call (gcall *stmt,
            && trans_map[j].unit_offset == apm->unit_offset)
          {
            repl = trans_map[j].repl;
+           if (!useless_type_conversion_p (apm->type, TREE_TYPE (repl)))
+             {
+               repl = build1 (VIEW_CONVERT_EXPR, apm->type, repl);
+               repl = force_gimple_operand_gsi (&gsi, repl, true, NULL, true,
+                                                GSI_SAME_STMT);
+             }
            break;
          }
       if (repl)

Reply via email to