[Bug ipa/113520] ICE with mismatched types with LTO (tree check: expected array_type, have integer_type in array_ref_low_bound)

2024-01-24 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113520

--- Comment #9 from Richard Biener  ---
(In reply to Jan Hubicka from comment #8)
> I think the ipa-cp summaries should be used only when types match. At least
> Martin added type streaming for all the jump functions.  So we are missing
> some check?

I don't think this applies here, we're having


foo ([5]);

with b being int vs int[], so it's not about the argument types matching
or the type of the JF but instead the value effectively changing during
streaming due to varpool node "merging".

As said elsewhere we avoid the issue by preserving the type of possibly
merged decls by wrapping it with a MEM_REF (for rvalues a V_C_E would
be possible as well).  And we unwrap it later when possible (but that's
of course optional).

I think any summary streaming referencing decls subject to WPA merging
need to do the same - it's not possible to recover after the fact since
the original type is lost (for the ARRAY_REF case it might be possible
to infer a type that would be good enough of course).

[Bug ipa/113520] ICE with mismatched types with LTO (tree check: expected array_type, have integer_type in array_ref_low_bound)

2024-01-24 Thread hubicka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113520

--- Comment #8 from Jan Hubicka  ---
I think the ipa-cp summaries should be used only when types match. At least
Martin added type streaming for all the jump functions.  So we are missing some
check?

[Bug ipa/113520] ICE with mismatched types with LTO (tree check: expected array_type, have integer_type in array_ref_low_bound)

2024-01-22 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113520

Richard Biener  changed:

   What|Removed |Added

   Keywords||diagnostic

--- Comment #7 from Richard Biener  ---
It's also a missing WPA diagnostic (OTOH one decl is just external and IIRC
we kind-of allow builtin_names[] to refer of a single element array
implemented as 'int builtin_names').

[Bug ipa/113520] ICE with mismatched types with LTO (tree check: expected array_type, have integer_type in array_ref_low_bound)

2024-01-22 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113520

Richard Biener  changed:

   What|Removed |Added

   Last reconfirmed||2024-01-22
  Component|tree-optimization   |ipa
 Ever confirmed|0   |1
 Status|UNCONFIRMED |NEW
 CC||hubicka at gcc dot gnu.org,
   ||jamborm at gcc dot gnu.org,
   ||rguenth at gcc dot gnu.org
   Keywords||lto

--- Comment #6 from Richard Biener  ---
Hmm, we are supposed to "handle" this during in-streaming.  This seems to work
but then for some reason it gets fiddled with again...

Ah, so this is reading of IPA CP summaries where it seems that we do not
apply these "tricks", gimple-streamer-out.cc has

  /* Wrap all uses of non-automatic variables inside MEM_REFs
 so that we do not have to deal with type mismatches on
 merged symbols during IL read in.  The first operand
 of GIMPLE_DEBUG must be a decl, not MEM_REF, though.  */
  if (!flag_wpa && op && (i || !is_gimple_debug (stmt)))
{
  basep = 
  if (TREE_CODE (*basep) == ADDR_EXPR)
basep = _OPERAND (*basep, 0);
  while (handled_component_p (*basep))
basep = _OPERAND (*basep, 0);
  if (VAR_P (*basep)
  && !auto_var_in_fn_p (*basep, fn->decl)
  && !DECL_REGISTER (*basep)) 
{
  bool volatilep = TREE_THIS_VOLATILE (*basep);
  tree ptrtype = build_pointer_type (TREE_TYPE (*basep));
  *basep = build2 (MEM_REF, TREE_TYPE (*basep),
   build1 (ADDR_EXPR, ptrtype, *basep),
   build_int_cst (ptrtype, 0));
  TREE_THIS_VOLATILE (*basep) = volatilep;
...

and gimple-streamer-in.cc undoes this when the prevailing decls are compatible:

  /* At LTO output time we wrap all global decls in MEM_REFs to
 allow seamless replacement with prevailing decls.  Undo this
 here if the prevailing decl allows for this.
 ???  Maybe we should simply fold all stmts.  */
  if (TREE_CODE (*opp) == MEM_REF
  && TREE_CODE (TREE_OPERAND (*opp, 0)) == ADDR_EXPR
  && integer_zerop (TREE_OPERAND (*opp, 1))
  && (TREE_THIS_VOLATILE (*opp)
  == TREE_THIS_VOLATILE
   (TREE_OPERAND (TREE_OPERAND (*opp, 0), 0)))
  && !TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (*opp, 1)))
  && (TREE_TYPE (*opp)
  == TREE_TYPE (TREE_TYPE (TREE_OPERAND (*opp, 1
  && (TREE_TYPE (*opp)
  == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (*opp, 0), 0
*opp = TREE_OPERAND (TREE_OPERAND (*opp, 0), 0);

I suppose we might want to split these out so summary streaming can apply
this to streamed trees as well?