@copying
@quotation
-GNAT Reference Manual , Oct 17, 2025
+GNAT Reference Manual , Oct 31, 2025
AdaCore
checks (at compile time if possible, generating a warning, or at execution
time with a run-time check) that the alignment is appropriate. If the
run-time check fails, then @code{Program_Error} is raised. This run-time
-check is suppressed if range checks are suppressed, or if the special GNAT
-check Alignment_Check is suppressed, or if
+check is suppressed if the GNAT check Alignment_Check is suppressed, or if
@code{pragma Restrictions (No_Elaboration_Code)} is in effect. It is also
suppressed by default on non-strict alignment machines (such as the x86).
Off : Boolean;
-- Whether the address is offset within Y in the second case
-
- Alignment_Checks_Suppressed : Boolean;
- -- Whether alignment checks are suppressed by an active scope suppress
- -- setting. We need to save the value in order to be able to reuse it
- -- after the back end has been run.
end record;
package Address_Clause_Checks is new Table.Table (
Table_Increment => 200,
Table_Name => "Address_Clause_Checks");
- function Alignment_Checks_Suppressed
- (ACCR : Address_Clause_Check_Record) return Boolean;
- -- Return whether the alignment check generated for the address clause
- -- is suppressed.
-
- ---------------------------------
- -- Alignment_Checks_Suppressed --
- ---------------------------------
-
- function Alignment_Checks_Suppressed
- (ACCR : Address_Clause_Check_Record) return Boolean
- is
- begin
- if Checks_May_Be_Suppressed (ACCR.X) then
- return Is_Check_Suppressed (ACCR.X, Alignment_Check);
- else
- return ACCR.Alignment_Checks_Suppressed;
- end if;
- end Alignment_Checks_Suppressed;
-
-----------------------------------------
-- Adjust_Record_For_Reverse_Bit_Order --
-----------------------------------------
end if;
end;
- -- Entity has delayed freeze, so we will generate an
+ -- The entity has delayed freeze, so we will generate an
-- alignment check at the freeze point unless suppressed.
+ -- We will unconditionally generate it when the alignment
+ -- is specified in addition to the address, to compensate
+ -- for the check being suppressed by default on machines
+ -- that do not need strict alignment of memory accesses.
- if not Range_Checks_Suppressed (U_Ent)
- and then not Alignment_Checks_Suppressed (U_Ent)
+ if not Alignment_Checks_Suppressed (U_Ent)
+ or else Present (Alignment_Clause (U_Ent))
then
Set_Check_Address_Alignment (N);
end if;
if Is_Array_Type (U_Ent) then
Set_Alignment (Base_Type (U_Ent), Align);
end if;
+
+ -- See the Attribute_Address case above for the rationale
+
+ if not Is_Type (U_Ent)
+ and then Present (Address_Clause (U_Ent))
+ then
+ Set_Check_Address_Alignment (Address_Clause (U_Ent));
+ end if;
end if;
end Alignment;
Y : Entity_Id;
Off : Boolean)
is
- ACS : constant Boolean := Scope_Suppress.Suppress (Alignment_Check);
begin
- Address_Clause_Checks.Append ((N, X, A, Y, Off, ACS));
+ Address_Clause_Checks.Append ((N, X, A, Y, Off));
end Register_Address_Clause_Check;
------------------------
-- Check for known value not multiple of alignment
if No (ACCR.Y) then
- if not Alignment_Checks_Suppressed (ACCR)
+ if Check_Address_Alignment (ACCR.N)
and then X_Alignment /= 0
and then ACCR.A mod X_Alignment /= 0
then
-- Note: we do not check the alignment if we gave a size
-- warning, since it would likely be redundant.
- elsif not Alignment_Checks_Suppressed (ACCR)
+ elsif Check_Address_Alignment (ACCR.N)
and then Y_Alignment /= Uint_0
and then
(Y_Alignment < X_Alignment