diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2025-04-07 10:33:52 +0200 |
---|---|---|
committer | Eric Botcazou <ebotcazou@adacore.com> | 2025-04-07 10:35:38 +0200 |
commit | f085dbf97ed4445830127c955909ff2b887ded69 (patch) | |
tree | 872fe7ad451fa659ee2428de30053726f2b2468e /gcc/ada/gcc-interface/utils.cc | |
parent | 0c63c7524bd523ea82933e90689b63d80e16d67e (diff) | |
download | gcc-f085dbf97ed4445830127c955909ff2b887ded69.zip gcc-f085dbf97ed4445830127c955909ff2b887ded69.tar.gz gcc-f085dbf97ed4445830127c955909ff2b887ded69.tar.bz2 |
Ada: Fix wrong 'Access to aliased constrained array of controlled type
For technical reasons, the recently reimplemented finalization machinery
for controlled types requires arrays of controlled types to be allocated
with their bounds, including in the case where their nominal subtype is
constrained. However, in this case, the type of 'Access for the arrays
is pointer-to-constrained-array and, therefore, its value must designate
the array itself and not the bounds.
gcc/ada/
* gcc-interface/utils.cc (convert) <POINTER_TYPE>: Use fold_convert
to convert between thin pointers. If the source is a thin pointer
with zero offset from the base and the target is a pointer to its
array, displace the pointer after converting it.
* gcc-interface/utils2.cc (build_unary_op) <ATTR_ADDR_EXPR>: Use
fold_convert to convert the address before displacing it.
Diffstat (limited to 'gcc/ada/gcc-interface/utils.cc')
-rw-r--r-- | gcc/ada/gcc-interface/utils.cc | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc index 1448716..9212827 100644 --- a/gcc/ada/gcc-interface/utils.cc +++ b/gcc/ada/gcc-interface/utils.cc @@ -5259,7 +5259,7 @@ convert (tree type, tree expr) : size_zero_node; tree byte_diff = size_diffop (type_pos, etype_pos); - expr = build1 (NOP_EXPR, type, expr); + expr = fold_convert (type, expr); if (integer_zerop (byte_diff)) return expr; @@ -5267,6 +5267,21 @@ convert (tree type, tree expr) fold_convert (sizetype, byte_diff)); } + /* If converting from a thin pointer with zero offset from the base to + a pointer to the array, add the offset of the array field. */ + if (TYPE_IS_THIN_POINTER_P (etype) + && !TYPE_UNCONSTRAINED_ARRAY (TREE_TYPE (etype))) + { + tree arr_field = DECL_CHAIN (TYPE_FIELDS (TREE_TYPE (etype))); + + if (TREE_TYPE (type) == TREE_TYPE (arr_field)) + { + expr = fold_convert (type, expr); + return build_binary_op (POINTER_PLUS_EXPR, type, expr, + byte_position (arr_field)); + } + } + /* If converting fat pointer to normal or thin pointer, get the pointer to the array and then convert it. */ if (TYPE_IS_FAT_POINTER_P (etype)) |