[Ada] Do not generate elaboration code for alignment aspect

gcc/ada/

	* einfo.ads (Delayed Freezing and Elaboration): Adjust description.
	* freeze.adb (Freeze_Object_Declaration): Likewise.
	* sem_ch3.adb (Delayed_Aspect_Present): Likewise.  Do not return
	true for Alignment.
	* sem_ch13.adb (Analyze_Aspect_Specifications): Do not always delay
	for Alignment.  Moreover, for Alignment and various Size aspects,
	do not delay if the expression is an attribute whose prefix is the
	Standard package.
This commit is contained in:
Eric Botcazou 2020-06-04 10:15:33 +02:00 committed by Pierre-Marie de Rodat
parent ae6fec84da
commit 4c1e539511
4 changed files with 21 additions and 9 deletions

View File

@ -281,8 +281,7 @@ package Einfo is
-- For object declarations, the flag is set when an address clause for the
-- object is encountered. Legality checks on the address expression only take
-- place at the freeze point of the object. In Ada 2012, the flag is also set
-- when an address or an alignment aspect for the object is encountered (note
-- the discrepancy with the non-aspect case).
-- when an address aspect for the object is encountered.
-- Most types have an explicit freeze node, because they cannot be elaborated
-- until all representation and operational items that apply to them have been

View File

@ -3431,7 +3431,7 @@ package body Freeze is
Check_Address_Clause (E);
-- Similar processing is needed for aspects that may affect object
-- layout, like Alignment, if there is an initialization expression.
-- layout, like Address, if there is an initialization expression.
-- We don't do this if there is a pragma Linker_Section, because it
-- would prevent the back end from statically initializing the
-- object; we don't want elaboration code in that case.

View File

@ -2861,17 +2861,30 @@ package body Sem_Ch13 is
if A_Id in Boolean_Aspects and then No (Expr) then
Delay_Required := False;
-- For non-Boolean aspects, don't delay if integer literal,
-- unless the aspect is Alignment, which affects the
-- freezing of an initialized object.
-- For non-Boolean aspects, don't delay if integer literal
elsif A_Id not in Boolean_Aspects
and then A_Id /= Aspect_Alignment
and then Present (Expr)
and then Nkind (Expr) = N_Integer_Literal
then
Delay_Required := False;
-- For Alignment and various Size aspects, don't delay for
-- an attribute reference whose prefix is Standard, for
-- example Standard'Maximum_Alignment or Standard'Word_Size.
elsif (A_Id = Aspect_Alignment
or else A_Id = Aspect_Component_Size
or else A_Id = Aspect_Object_Size
or else A_Id = Aspect_Size
or else A_Id = Aspect_Value_Size)
and then Present (Expr)
and then Nkind (Expr) = N_Attribute_Reference
and then Nkind (Prefix (Expr)) = N_Identifier
and then Chars (Prefix (Expr)) = Name_Standard
then
Delay_Required := False;
-- All other cases are delayed
else

View File

@ -3668,7 +3668,7 @@ package body Sem_Ch3 is
-- has aspects that require delayed analysis, the resolution of the
-- aggregate must be deferred to the freeze point of the object. This
-- special processing was created for address clauses, but it must
-- also apply to Alignment. This must be done before the aspect
-- also apply to address aspects. This must be done before the aspect
-- specifications are analyzed because we must handle the aggregate
-- before the analysis of the object declaration is complete.
@ -3896,7 +3896,7 @@ package body Sem_Ch3 is
while Present (A) loop
A_Id := Get_Aspect_Id (Chars (Identifier (A)));
if A_Id = Aspect_Alignment or else A_Id = Aspect_Address then
if A_Id = Aspect_Address then
-- Set flag on object entity, for later processing at
-- the freeze point.