]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Clear confusion about Standard'Maximum_Alignment
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 22 Oct 2025 17:59:54 +0000 (19:59 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 13 Nov 2025 15:26:57 +0000 (16:26 +0100)
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.

gcc/ada/checks.adb
gcc/ada/doc/gnat_rm/implementation_defined_attributes.rst
gcc/ada/doc/gnat_rm/representation_clauses_and_pragmas.rst
gcc/ada/gnat_rm.texi
gcc/ada/sem_ch13.adb
gcc/ada/ttypes.ads

index 39cf37ea711bb38a65e6609c9d71f9c5739f1c03..0577a9ec53d264459ff4e16cbbef9764a5f984bd 100644 (file)
@@ -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;
 
index 86d2a815e1e0961320cc912151312a24b79b326c..29d2e0d5e76f6280f66657efabce3242ec607d9c 100644 (file)
@@ -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
 ==========================
index 65bb1877f7c637fcaeb4c170003858e2f3672ebc..177f5bbfcd2c21a8faa80499fbfa66be39d2fbeb 100644 (file)
@@ -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
 
index ee0554899e91fe3152f16c1660359c2fcb947be2..30dba8215a4cfed553e82c771c9238be1df4e635 100644 (file)
@@ -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
 
index 31af1bb4675cda2b46f02a749e60aa7f145ed394..46eb08e38f13791d17a48555ea0bec9a5cef34ef 100644 (file)
@@ -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
index fa3622d3c0b9fdffcf2e9b46d48780fd3f129860..1eab19705da90a5845289da480f304ea36c8156e 100644 (file)
@@ -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;