]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix missing error on too large Component_Size not multiple of storage unit
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 1 May 2025 23:30:56 +0000 (01:30 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 3 Jul 2025 08:16:29 +0000 (10:16 +0200)
This is a small regression introduced a few years ago.

gcc/ada/ChangeLog:

* gcc-interface/decl.cc (gnat_to_gnu_component_type): Validate the
Component_Size like the size of a type only if the component type
is actually packed.

gcc/ada/gcc-interface/decl.cc

index 972607a917b06ae7532832323b55dca75002ab22..1d9832d69ad4b39032269f5ee9e43d588e7d7ee8 100644 (file)
@@ -5444,7 +5444,7 @@ gnat_to_gnu_component_type (Entity_Id gnat_array, bool definition,
   const bool is_bit_packed = Is_Bit_Packed_Array (gnat_array);
   tree gnu_type = gnat_to_gnu_type (gnat_type);
   tree gnu_comp_size;
-  bool has_packed_components;
+  bool has_packed_component;
   unsigned int max_align;
 
   /* If an alignment is specified, use it as a cap on the component type
@@ -5465,16 +5465,22 @@ gnat_to_gnu_component_type (Entity_Id gnat_array, bool definition,
       && !TYPE_FAT_POINTER_P (gnu_type)
       && tree_fits_uhwi_p (TYPE_SIZE (gnu_type)))
     {
-      gnu_type = make_packable_type (gnu_type, false, max_align);
-      has_packed_components = true;
+      tree gnu_packable_type = make_packable_type (gnu_type, false, max_align);
+      if (gnu_packable_type != gnu_type)
+       {
+         gnu_type = gnu_packable_type;
+         has_packed_component = true;
+       }
+      else
+       has_packed_component = false;
     }
   else
-    has_packed_components = is_bit_packed;
+    has_packed_component = is_bit_packed;
 
   /* Get and validate any specified Component_Size.  */
   gnu_comp_size
     = validate_size (Component_Size (gnat_array), gnu_type, gnat_array,
-                    has_packed_components ? TYPE_DECL : VAR_DECL, true,
+                    has_packed_component ? TYPE_DECL : VAR_DECL, true,
                     Has_Component_Size_Clause (gnat_array), NULL, NULL);
 
   /* If the component type is a RECORD_TYPE that has a self-referential size,