https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119792
--- Comment #15 from rguenther at suse dot de <rguenther at suse dot de> --- On Thu, 17 Apr 2025, ebotcazou at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119792 > > --- Comment #14 from Eric Botcazou <ebotcazou at gcc dot gnu.org> --- > > FWIW, when I restore my patch on GCC-14 and add the size check to > > useless_type_conversion_p, this then fixes the Ada test case. > > > > diff --git a/gcc/gimple-expr.cc b/gcc/gimple-expr.cc > > index 0477c9d5f44..79ac3d35350 100644 > > --- a/gcc/gimple-expr.cc > > +++ b/gcc/gimple-expr.cc > > @@ -283,7 +283,11 @@ useless_type_conversion_p (tree outer_type, tree > > inner_type) > > else if (AGGREGATE_TYPE_P (inner_type) > > && TREE_CODE (inner_type) == TREE_CODE (outer_type)) > > return TYPE_CANONICAL (inner_type) > > - && TYPE_CANONICAL (inner_type) == TYPE_CANONICAL (outer_type); > > + && TYPE_CANONICAL (inner_type) == TYPE_CANONICAL (outer_type) > > + && TREE_CODE (TYPE_SIZE (inner_type)) == INTEGER_CST > > + && TREE_CODE (TYPE_SIZE (outer_type)) == INTEGER_CST > > + && tree_int_cst_equal (TYPE_SIZE (outer_type), > > + TYPE_SIZE (inner_type)); > > But will very likely introduce other regressions, because a lot of types do > not > have a fixed size in Ada. I'd at least use operand_equal_p (TYPE_SIZE (inner_type), TYPE_SIZE (outer_type)) for this reason. Also note you might arrive with TYPE_SIZE (...) == NULL_TREE, so you should handle incomplete types in some reasonable way here. Eric, can you try to read through https://gcc.gnu.org/wiki/document-middle-end-type-system and amend it with comments about Ada? I'm especially curios what exactly the properties are that are not useless in the VIEW_CONVERT_EXPRs that get wrongly stripped here?