[COMMITTED] ada: Fix bogus Constraint_Error on allocator for access to array of access type
Checks
Commit Message
From: Eric Botcazou <ebotcazou@adacore.com>
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.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/gcc-interface/decl.cc | 6 +++---
gcc/ada/gcc-interface/utils.cc | 3 ++-
2 files changed, 5 insertions(+), 4 deletions(-)
@@ -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
@@ -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: