https://gcc.gnu.org/g:e77d45d70e6c80f0bbdafeec20298a08da715048

commit r16-5229-ge77d45d70e6c80f0bbdafeec20298a08da715048
Author: Eric Botcazou <[email protected]>
Date:   Wed Oct 22 19:59:54 2025 +0200

    ada: Clear confusion about Standard'Maximum_Alignment
    
    This documents the meaning of Standard'Maximum_Alignment as it has been
    implemented in the GCC-based compiler for more than a decade.
    
    gcc/ada/ChangeLog:
    
            * doc/gnat_rm/implementation_defined_attributes.rst
            (Maximum_Alignment): Fix description.
            * doc/gnat_rm/representation_clauses_and_pragmas.rst
            (Alignment Clauses): Adjust accordingly.
            * checks.adb (Apply_Address_Clause_Check): Remove incorrect test on
            Maximum_Alignment.
            * sem_ch13.adb (Analyze_Attribute_Definition_Clause): Minor tweak
            in comment.
            * ttypes.ads (Maximum_Alignment): Fix description.
            * gnat_rm.texi: Regenerate.

Diff:
---
 gcc/ada/checks.adb                                     |  8 ++------
 .../doc/gnat_rm/implementation_defined_attributes.rst  | 11 ++++++-----
 .../doc/gnat_rm/representation_clauses_and_pragmas.rst |  7 +++----
 gcc/ada/gnat_rm.texi                                   | 18 +++++++++---------
 gcc/ada/sem_ch13.adb                                   |  2 +-
 gcc/ada/ttypes.ads                                     |  6 ++++--
 6 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index 39cf37ea711b..0577a9ec53d2 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -590,8 +590,7 @@ package body Checks is
       --  reset to reference the value expression of the constant).
 
    begin
-      --  See if alignment check needed. Note that we never need a check if the
-      --  maximum alignment is one, since the check will always succeed.
+      --  See if alignment check needed
 
       --  Note: we do not check for checks suppressed here, since that check
       --  was done in Sem_Ch13 when the address clause was processed. We are
@@ -601,10 +600,7 @@ package body Checks is
       --  check the status of check suppressing at the point of the address
       --  clause.
 
-      if No (AC)
-        or else not Check_Address_Alignment (AC)
-        or else Maximum_Alignment = 1
-      then
+      if No (AC) or else not Check_Address_Alignment (AC) then
          return;
       end if;
 
diff --git a/gcc/ada/doc/gnat_rm/implementation_defined_attributes.rst 
b/gcc/ada/doc/gnat_rm/implementation_defined_attributes.rst
index 86d2a815e1e0..29d2e0d5e76f 100644
--- a/gcc/ada/doc/gnat_rm/implementation_defined_attributes.rst
+++ b/gcc/ada/doc/gnat_rm/implementation_defined_attributes.rst
@@ -653,11 +653,12 @@ Attribute Maximum_Alignment
 
 .. index:: Maximum_Alignment
 
-``Standard'Maximum_Alignment`` (``Standard`` is the only
-allowed prefix) provides the maximum useful alignment value for the
-target.  This is a static value that can be used to specify the alignment
-for an object, guaranteeing that it is properly aligned in all
-cases.
+``Standard'Maximum_Alignment`` (``Standard`` is the only allowed prefix)
+provides the maximum default alignment value for the target, that is to
+say the maximum alignment that the compiler may choose by default for a
+type or an object. Larger alignments are supported up to some maximum
+value dependent on the target, but may require specific mechanisms that
+are not needed up to ``Standard'Maximum_Alignment``.
 
 Attribute Max_Integer_Size
 ==========================
diff --git a/gcc/ada/doc/gnat_rm/representation_clauses_and_pragmas.rst 
b/gcc/ada/doc/gnat_rm/representation_clauses_and_pragmas.rst
index 65bb1877f7c6..177f5bbfcd2c 100644
--- a/gcc/ada/doc/gnat_rm/representation_clauses_and_pragmas.rst
+++ b/gcc/ada/doc/gnat_rm/representation_clauses_and_pragmas.rst
@@ -40,8 +40,8 @@ The default alignment values are as follows:
 
   For elementary types, the alignment is the minimum of the actual size of
   objects of the type divided by ``Storage_Unit``,
-  and the maximum alignment supported by the target.
-  (This maximum alignment is given by the GNAT-specific attribute
+  and the maximum default alignment supported by the target.
+  (This maximum default alignment is given by the GNAT-specific attribute
   ``Standard'Maximum_Alignment``; see :ref:`Attribute_Maximum_Alignment`.)
 
   .. index:: Maximum_Alignment attribute
@@ -96,8 +96,7 @@ The default alignment values are as follows:
   strict alignment.
 
 An alignment clause may specify a larger alignment than the default value
-up to some maximum value dependent on the target (obtainable by using the
-attribute reference ``Standard'Maximum_Alignment``). It may also specify
+up to some maximum value dependent on the target. It may also specify
 a smaller alignment than the default value for enumeration, integer and
 fixed point types, as well as for record types, for example
 
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index ee0554899e91..30dba8215a4c 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -11583,11 +11583,12 @@ this attribute.
 
 @geindex Maximum_Alignment
 
-@code{Standard'Maximum_Alignment} (@code{Standard} is the only
-allowed prefix) provides the maximum useful alignment value for the
-target.  This is a static value that can be used to specify the alignment
-for an object, guaranteeing that it is properly aligned in all
-cases.
+@code{Standard'Maximum_Alignment} (@code{Standard} is the only allowed prefix)
+provides the maximum default alignment value for the target, that is to
+say the maximum alignment that the compiler may choose by default for a
+type or an object. Larger alignments are supported up to some maximum
+value dependent on the target, but may require specific mechanisms that
+are not needed up to @code{Standard'Maximum_Alignment}.
 
 @node Attribute Max_Integer_Size,Attribute Mechanism_Code,Attribute 
Maximum_Alignment,Implementation Defined Attributes
 @anchor{gnat_rm/implementation_defined_attributes 
attribute-max-integer-size}@anchor{1aa}
@@ -19061,8 +19062,8 @@ The default alignment values are as follows:
 
 For elementary types, the alignment is the minimum of the actual size of
 objects of the type divided by @code{Storage_Unit},
-and the maximum alignment supported by the target.
-(This maximum alignment is given by the GNAT-specific attribute
+and the maximum default alignment supported by the target.
+(This maximum default alignment is given by the GNAT-specific attribute
 @code{Standard'Maximum_Alignment}; see @ref{1a8,,Attribute Maximum_Alignment}.)
 
 @geindex Maximum_Alignment attribute
@@ -19126,8 +19127,7 @@ strict alignment.
 @end itemize
 
 An alignment clause may specify a larger alignment than the default value
-up to some maximum value dependent on the target (obtainable by using the
-attribute reference @code{Standard'Maximum_Alignment}). It may also specify
+up to some maximum value dependent on the target. It may also specify
 a smaller alignment than the default value for enumeration, integer and
 fixed point types, as well as for record types, for example
 
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 31af1bb4675c..46eb08e38f13 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -7108,7 +7108,7 @@ package body Sem_Ch13 is
                Set_Has_Alignment_Clause (U_Ent);
 
                --  Tagged type case, check for attempt to set alignment to a
-               --  value greater than Max_Align, and reset if so.
+               --  value greater than Maximum_Alignment, and reset if so.
 
                if Is_Tagged_Type (U_Ent) and then Align > Max_Align then
                   Error_Msg_N
diff --git a/gcc/ada/ttypes.ads b/gcc/ada/ttypes.ads
index fa3622d3c0b9..1eab19705da9 100644
--- a/gcc/ada/ttypes.ads
+++ b/gcc/ada/ttypes.ads
@@ -177,8 +177,10 @@ package Ttypes is
    ----------------------------------------
 
    Maximum_Alignment : constant Pos := Set_Targ.Maximum_Alignment;
-   --  The maximum alignment, in storage units, that an object or type may
-   --  require on the target machine.
+   --  The maximum default alignment, in storage units, that an object or type
+   --  may require on the target machine. The implementation must never choose
+   --  a larger alignment on its own, that is to say when it is not explicitly
+   --  requested by an alignment aspect/clause in the source code.
 
    System_Allocator_Alignment : constant Pos :=
                                   Set_Targ.System_Allocator_Alignment;

Reply via email to