]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix ancient bug in pragma Suppress (Alignment_Check)
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 23 Oct 2025 17:20:49 +0000 (19:20 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 13 Nov 2025 15:26:58 +0000 (16:26 +0100)
The recent change that streamlined the implementation of alignment checks
has uncovered an ancient bug in the implementation of pragma Suppress on
a specific object:

  pragma Suppress (Alignment_Check, A);

The pragma would work only if placed before the address clause:

  A : Integer;
  pragma Suppress (Alignment_Check, A);
  for A'Address use ...

but not if placed (just) after it:

  A : Integer;
  for A'Address use ...
  pragma Suppress (Alignment_Check, A);

which seems unfriendly at best.

gcc/ada/ChangeLog:

* sem_prag.adb (Analyze_Pragma) <Process_Suppress_Unsuppress>: For
Alignment_Check on a specific object with an address clause and no
alignment clause, toggle the Check_Address_Alignment flag present
on the address clause.

gcc/ada/sem_prag.adb

index 0ebf421fc96f9bcb3b65d4d693308bb9a5b235ac..88558a354784c63737d99ebb8a933960804b7283 100644 (file)
@@ -11995,6 +11995,26 @@ package body Sem_Prag is
             if Is_First_Subtype (E) and then Etype (E) /= E then
                Suppress_Unsuppress_Echeck (Etype (E), C);
             end if;
+
+            --  For the alignment check of an object with an address clause,
+            --  we want the pragma to be taken into account even if it comes
+            --  after the address clause:
+
+            --    A : Integer;
+            --    for A'Address use ...
+            --    pragma Suppress (Alignment_Check, A);
+
+            --  When there is also an alignment clause, the check is generated
+            --  unconditionally, see Analyze_Attribute_Definition_Clause.
+
+            if C = Alignment_Check
+              and then not Is_Type (E)
+              and then Present (Address_Clause (E))
+              and then No (Alignment_Clause (E))
+            then
+               Set_Check_Address_Alignment
+                 (Address_Clause (E), not Suppress_Case);
+            end if;
          end Suppress_Unsuppress_Echeck;
 
       --  Start of processing for Process_Suppress_Unsuppress