]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix extended access and memory pool explicit deref
authorMarc Poulhiès <poulhies@adacore.com>
Tue, 16 Sep 2025 13:07:29 +0000 (15:07 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 6 Oct 2025 12:27:09 +0000 (14:27 +0200)
Explicit dereference of an extended access with data allocation in a
memory pool would crash the compiler.

gcc/ada/ChangeLog:

* gcc-interface/trans.cc (Attribute_to_gnu)<Attr_Pool_Address>: Handle
extended access.

gcc/ada/gcc-interface/trans.cc

index e80002e31113e7beb3ffcae6c9048b6da8d8b5bc..cdbd4828c82545ce9481945dfa4e24135ad31794 100644 (file)
@@ -1937,12 +1937,17 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p,
        tree gnu_ptr = gnu_prefix;
        tree gnu_obj_type;
 
-       gnu_result_type = get_unpadded_type (Etype (gnat_node));
-
-       /* If this is fat pointer, the object must have been allocated with the
-          template in front of the array.  So compute the template address; do
-          it by converting to a thin pointer.  */
-       if (TYPE_IS_FAT_POINTER_P (TREE_TYPE (gnu_ptr)))
+        if (Is_Extended_Access_Type (Etype (Prefix (gnat_node)))
+            && !Is_Constrained (Etype (gnat_node)))
+          gnu_result_type = get_unpadded_extended_type (Etype (gnat_node));
+        else
+          gnu_result_type = get_unpadded_type (Etype (gnat_node));
+
+       /* If this is fat or extended pointer, the object must have been
+          allocated with the template in front of the array.  So compute the
+          template address; do it by converting to a thin pointer.  */
+       if (TYPE_IS_FAT_POINTER_P (TREE_TYPE (gnu_ptr))
+            || TYPE_IS_EXTENDED_POINTER_P (TREE_TYPE (gnu_ptr)))
          gnu_ptr
            = convert (build_pointer_type
                       (TYPE_OBJECT_RECORD_TYPE