From: Eric Botcazou Date: Thu, 4 Jun 2020 08:15:33 +0000 (+0200) Subject: [Ada] Do not generate elaboration code for alignment aspect X-Git-Tag: upstream/12.2.0~14825 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4c1e539511beba77c4bc803a2f86bc91e37d6827;p=platform%2Fupstream%2Fgcc.git [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. --- diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads index f3a042a..bea4db0 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 74d15b5..ff54188 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 7445536..5937ce2 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 435c69f..f0a588f 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.