]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Do not use ATTR_ADDR_EXPR for 'Unrestricted_Access
authorEric Botcazou <ebotcazou@adacore.come>
Mon, 11 Nov 2024 10:16:26 +0000 (11:16 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 26 Nov 2024 09:49:36 +0000 (10:49 +0100)
Unlike for 'Access or 'Unchecked_Access, the Attribute_to_gnu routine passes
ATTR_ADDR_EXPR to build_unary_op for 'Unrestricted_Access, which causes the
processing done in build_unary_op to flatten the reference, in particular to
remove all intermediate (view) conversions, which may be problematic for the
SUBSTITUTE_PLACEHOLDER_IN_EXPR machinery.

gcc/ada/ChangeLog:

* gcc-interface/trans.cc (Attribute_to_gnu) <Attr_Access>: Do not
pass ATTR_ADDR_EXPR to build_unary_op for 'Unrestricted_Access.

gcc/ada/gcc-interface/trans.cc

index 5d971c1681d6bddfd544ec153af5a2ae0e393ef6..3aa41253d74c08ee23c806aa2d3d0976b4031099 100644 (file)
@@ -1840,10 +1840,15 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p,
       gcc_assert (TREE_CODE (gnu_prefix) != TYPE_DECL);
 
       gnu_result_type = get_unpadded_type (Etype (gnat_node));
+
+      /* We used to pass ATTR_ADDR_EXPR for Attr_Unrestricted_Access too, but
+        the processing done in build_unary_op for it flattens the reference,
+        in particular removes all intermediate (view) conversions, which may
+        cause SUBSTITUTE_PLACEHOLDER_IN_EXPR to fail to substitute in the
+        bounds of a fat pointer returned for Attr_Unrestricted_Access.  */
       gnu_result
-       = build_unary_op (((attribute == Attr_Address
-                           || attribute == Attr_Unrestricted_Access)
-                          && !Must_Be_Byte_Aligned (gnat_node))
+       = build_unary_op (attribute == Attr_Address
+                         && !Must_Be_Byte_Aligned (gnat_node)
                          ? ATTR_ADDR_EXPR : ADDR_EXPR,
                          gnu_result_type, gnu_prefix);