https://gcc.gnu.org/g:433fcdb6a2c0d5e80c95f58527228802726f8f0e

commit r15-9926-g433fcdb6a2c0d5e80c95f58527228802726f8f0e
Author: Eric Botcazou <ebotca...@adacore.com>
Date:   Tue Jun 24 20:32:46 2025 +0200

    ada: Fix alignment violation for chain of aligned and misaligned composite 
types
    
    This happens when aggressive optimizations are enabled (i.e. -O2 and above)
    because the ivopts pass fails to properly mark the new memory accesses it is
    creating as misaligned by means of the build_aligned_type function.
    
    gcc/ada/ChangeLog:
    
            * gcc-interface/utils.cc (make_packable_type): Clear the TYPE_PACKED
            flag in the case where the alignment is bumped.

Diff:
---
 gcc/ada/gcc-interface/utils.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc
index 9212827aecfe..20355a21e1a1 100644
--- a/gcc/ada/gcc-interface/utils.cc
+++ b/gcc/ada/gcc-interface/utils.cc
@@ -1225,7 +1225,6 @@ make_packable_type (tree type, bool in_record, unsigned 
int max_align)
      Note that we rely on the pointer equality created here for
      TYPE_NAME to look through conversions in various places.  */
   TYPE_NAME (new_type) = TYPE_NAME (type);
-  TYPE_PACKED (new_type) = 1;
   TYPE_JUSTIFIED_MODULAR_P (new_type) = TYPE_JUSTIFIED_MODULAR_P (type);
   TYPE_CONTAINS_TEMPLATE_P (new_type) = TYPE_CONTAINS_TEMPLATE_P (type);
   TYPE_REVERSE_STORAGE_ORDER (new_type) = TYPE_REVERSE_STORAGE_ORDER (type);
@@ -1240,6 +1239,8 @@ make_packable_type (tree type, bool in_record, unsigned 
int max_align)
       new_size = ceil_pow2 (size);
       new_align = MIN (new_size, BIGGEST_ALIGNMENT);
       SET_TYPE_ALIGN (new_type, new_align);
+      /* build_aligned_type needs to be able to adjust back the alignment.  */
+      TYPE_PACKED (new_type) = 0;
     }
   else
     {
@@ -1261,6 +1262,7 @@ make_packable_type (tree type, bool in_record, unsigned 
int max_align)
       if (max_align > 0 && new_align > max_align)
        new_align = max_align;
       SET_TYPE_ALIGN (new_type, MIN (align, new_align));
+      TYPE_PACKED (new_type) = 1;
     }
 
   TYPE_USER_ALIGN (new_type) = 1;

Reply via email to