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

--- Comment #23 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
> This was based on a discussion with Richard.  TYPE_CANONICAL is used for
> aliasing decisions and the FE must set it to from equivalence classes for
> types that are compatible.  In C, the types
> 
> int[];
> int[3];
> int[n];
> 
> are compatible, and this means that also the following types
> are compatible:
> 
> struct foo { int a; int b[]; };
> struct foo { int a; int b[3]; };
> struct foo { int a; int b[n]; };
> 
> Treating them as not compatible (by setting different TYPE_CANONICAL) causes
> subtle miscompilation issues in C.  I wonder how this works in Ada?

In Ada, array types are compatible (essentially) if they have the same range
(lb, ub) and the same component type T:

  type Arr is array (lb .. ub) of T;

and recursively when they are components of record types:

  type Rec is record
     I : Integer;
     A : Arr;
  end record;

That's exactly what has been implemented by the GCC system for 2 decades, see
for example gimple_canonical_types_compatible_p and hash_canonical_type.

Can't the very peculiar C rules be implemented by means of a language hook?

Reply via email to