From: Eric Botcazou Date: Tue, 12 Dec 2023 09:17:19 +0000 (+0100) Subject: ada: Fix bogus Constraint_Error on allocator for access to array of access type X-Git-Tag: basepoints/gcc-15~3077 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bcf7ebba9115cc1e0e1be4c6e00728e0e99e5fc8;p=thirdparty%2Fgcc.git ada: Fix bogus Constraint_Error on allocator for access to array of access type This occurs because the access element type is not its own TYPE_CANONICAL, which creates a discrepancy between the aliasing support code, which deals with types directly, and the middle-end which looks at TYPE_CANONICAL only. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) : Use the TYPE_CANONICAL of types when it comes to aliasing. * gcc-interface/utils.cc (relate_alias_sets): Likewise. --- diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc index 221baebb554e..93cfcb74fbf9 100644 --- a/gcc/ada/gcc-interface/decl.cc +++ b/gcc/ada/gcc-interface/decl.cc @@ -2185,8 +2185,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) if (COMPLETE_TYPE_P (gnu_fat_type)) { fld = TYPE_FIELDS (gnu_fat_type); - if (TYPE_ALIAS_SET_KNOWN_P (TREE_TYPE (fld))) - ptr_set = TYPE_ALIAS_SET (TREE_TYPE (fld)); + if (TYPE_ALIAS_SET_KNOWN_P (TYPE_CANONICAL (TREE_TYPE (fld)))) + ptr_set = TYPE_ALIAS_SET (TYPE_CANONICAL (TREE_TYPE (fld))); TREE_TYPE (fld) = ptr_type_node; TREE_TYPE (DECL_CHAIN (fld)) = gnu_ptr_template; TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (gnu_fat_type)) = 0; @@ -2417,7 +2417,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) else TREE_TYPE (fld) = build_pointer_type (tem); if (ptr_set != -1) - TYPE_ALIAS_SET (TREE_TYPE (fld)) = ptr_set; + TYPE_ALIAS_SET (TYPE_CANONICAL (TREE_TYPE (fld))) = ptr_set; /* If the maximum size doesn't overflow, use it. */ if (gnu_max_size diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc index bc063c203875..b3aae5bda52f 100644 --- a/gcc/ada/gcc-interface/utils.cc +++ b/gcc/ada/gcc-interface/utils.cc @@ -1867,7 +1867,8 @@ relate_alias_sets (tree new_type, tree old_type, enum alias_set_op op) && TYPE_NONALIASED_COMPONENT (new_type) != TYPE_NONALIASED_COMPONENT (old_type))); - TYPE_ALIAS_SET (new_type) = get_alias_set (old_type); + /* The alias set always lives on the TYPE_CANONICAL. */ + TYPE_ALIAS_SET (TYPE_CANONICAL (new_type)) = get_alias_set (old_type); break; case ALIAS_SET_SUBSET: