]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix bogus Constraint_Error on allocator for access to array of access type
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 12 Dec 2023 09:17:19 +0000 (10:17 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 9 Jan 2024 13:13:32 +0000 (14:13 +0100)
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) <E_Array_Type>: Use the
TYPE_CANONICAL of types when it comes to aliasing.
* gcc-interface/utils.cc (relate_alias_sets): Likewise.

gcc/ada/gcc-interface/decl.cc
gcc/ada/gcc-interface/utils.cc

index 221baebb554e8fa37f02f281dcdc6574c38ad91d..93cfcb74fbf9e8ceb0cfed96dba13049dbff33ef 100644 (file)
@@ -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
index bc063c203875d397b9864aefc0312e9872fedb6c..b3aae5bda52f5fe72055953bfb2bd77330863342 100644 (file)
@@ -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: