From 4c1e539511beba77c4bc803a2f86bc91e37d6827 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Thu, 4 Jun 2020 10:15:33 +0200 Subject: [PATCH] [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. --- gcc/ada/einfo.ads | 3 +-- gcc/ada/freeze.adb | 2 +- gcc/ada/sem_ch13.adb | 21 +++++++++++++++++---- gcc/ada/sem_ch3.adb | 4 ++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads index f3a042a4b9f..bea4db02471 100644 --- a/gcc/ada/einfo.ads +++ b/gcc/ada/einfo.ads @@ -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 diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index 74d15b57e8b..ff5418856ec 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -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. diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 74455361412..5937ce2bfe3 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -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 diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index 435c69f7b3d..f0a588fc112 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -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. -- 2.30.2