public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-2196] [Ada] Decouple analysis of static expression functions from GNATprove Date: Fri, 9 Jul 2021 12:38:12 +0000 (GMT) [thread overview] Message-ID: <20210709123812.7B34D3AAB465@sourceware.org> (raw) https://gcc.gnu.org/g:e40f4ab46364c3e16c35c4d96c89187e8cae5a65 commit r12-2196-ge40f4ab46364c3e16c35c4d96c89187e8cae5a65 Author: Piotr Trojanek <trojanek@adacore.com> Date: Fri May 28 15:11:03 2021 +0200 [Ada] Decouple analysis of static expression functions from GNATprove gcc/ada/ * sem_ch6.adb (Analyze_Expression_Function): Reorder code. Diff: --- gcc/ada/sem_ch6.adb | 137 ++++++++++++++++++++++++++-------------------------- 1 file changed, 68 insertions(+), 69 deletions(-) diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb index a3240143702..0ecac3fed4e 100644 --- a/gcc/ada/sem_ch6.adb +++ b/gcc/ada/sem_ch6.adb @@ -526,30 +526,30 @@ package body Sem_Ch6 is End_Scope; end if; + -- If this is a wrapper created in an instance for a formal + -- subprogram, insert body after declaration, to be analyzed when the + -- enclosing instance is analyzed. + + if GNATprove_Mode + and then Is_Generic_Actual_Subprogram (Def_Id) + then + Insert_After (N, New_Body); + -- To prevent premature freeze action, insert the new body at the end -- of the current declarations, or at the end of the package spec. -- However, resolve usage names now, to prevent spurious visibility -- on later entities. Note that the function can now be called in - -- the current declarative part, which will appear to be prior to - -- the presence of the body in the code. There are nevertheless no - -- order of elaboration issues because all name resolution has taken - -- place at the point of declaration. - - declare - Decls : List_Id := List_Containing (N); - Par : constant Node_Id := Parent (Decls); + -- the current declarative part, which will appear to be prior to the + -- presence of the body in the code. There are nevertheless no order + -- of elaboration issues because all name resolution has taken place + -- at the point of declaration. - begin - -- If this is a wrapper created in an instance for a formal - -- subprogram, insert body after declaration, to be analyzed when - -- the enclosing instance is analyzed. - - if GNATprove_Mode - and then Is_Generic_Actual_Subprogram (Def_Id) - then - Insert_After (N, New_Body); + else + declare + Decls : List_Id := List_Containing (N); + Par : constant Node_Id := Parent (Decls); - else + begin if Nkind (Par) = N_Package_Specification and then Decls = Visible_Declarations (Par) and then not Is_Empty_List (Private_Declarations (Par)) @@ -558,68 +558,67 @@ package body Sem_Ch6 is end if; Insert_After (Last (Decls), New_Body); + end; + end if; - -- Preanalyze the expression if not already done above + -- Preanalyze the expression if not already done above - if not Inside_A_Generic then - Push_Scope (Def_Id); - Install_Formals (Def_Id); - Preanalyze_Formal_Expression (Expr, Typ); - Check_Limited_Return (Orig_N, Expr, Typ); - End_Scope; - end if; + if not Inside_A_Generic then + Push_Scope (Def_Id); + Install_Formals (Def_Id); + Preanalyze_Formal_Expression (Expr, Typ); + Check_Limited_Return (Orig_N, Expr, Typ); + End_Scope; + end if; - -- In the case of an expression function marked with the - -- aspect Static, we need to check the requirement that the - -- function's expression is a potentially static expression. - -- This is done by making a full copy of the expression tree - -- and performing a special preanalysis on that tree with - -- the global flag Checking_Potentially_Static_Expression - -- enabled. If the resulting expression is static, then it's - -- OK, but if not, that means the expression violates the - -- requirements of the Ada 2022 RM in 4.9(3.2/5-3.4/5) and - -- we flag an error. - - if Is_Static_Function (Def_Id) then - if not Is_Static_Expression (Expr) then - declare - Exp_Copy : constant Node_Id := New_Copy_Tree (Expr); - begin - Set_Checking_Potentially_Static_Expression (True); + -- In the case of an expression function marked with the aspect + -- Static, we need to check the requirement that the function's + -- expression is a potentially static expression. This is done + -- by making a full copy of the expression tree and performing + -- a special preanalysis on that tree with the global flag + -- Checking_Potentially_Static_Expression enabled. If the + -- resulting expression is static, then it's OK, but if not, that + -- means the expression violates the requirements of the Ada 2022 + -- RM in 4.9(3.2/5-3.4/5) and we flag an error. - Preanalyze_Formal_Expression (Exp_Copy, Typ); + if Is_Static_Function (Def_Id) then + if not Is_Static_Expression (Expr) then + declare + Exp_Copy : constant Node_Id := New_Copy_Tree (Expr); + begin + Set_Checking_Potentially_Static_Expression (True); - if not Is_Static_Expression (Exp_Copy) then - Error_Msg_N - ("static expression function requires " - & "potentially static expression", Expr); - end if; + Preanalyze_Formal_Expression (Exp_Copy, Typ); - Set_Checking_Potentially_Static_Expression (False); - end; + if not Is_Static_Expression (Exp_Copy) then + Error_Msg_N + ("static expression function requires " + & "potentially static expression", Expr); end if; - -- We also make an additional copy of the expression and - -- replace the expression of the expression function with - -- this copy, because the currently present expression is - -- now associated with the body created for the static - -- expression function, which will later be analyzed and - -- possibly rewritten, and we need to have the separate - -- unanalyzed copy available for use with later static - -- calls. + Set_Checking_Potentially_Static_Expression (False); + end; + end if; - Set_Expression - (Original_Node (Subprogram_Spec (Def_Id)), - New_Copy_Tree (Expr)); + -- We also make an additional copy of the expression and + -- replace the expression of the expression function with + -- this copy, because the currently present expression is + -- now associated with the body created for the static + -- expression function, which will later be analyzed and + -- possibly rewritten, and we need to have the separate + -- unanalyzed copy available for use with later static + -- calls. - -- Mark static expression functions as inlined, to ensure - -- that even calls with nonstatic actuals will be inlined. + Set_Expression + (Original_Node (Subprogram_Spec (Def_Id)), + New_Copy_Tree (Expr)); - Set_Has_Pragma_Inline (Def_Id); - Set_Is_Inlined (Def_Id); - end if; - end if; - end; + -- Mark static expression functions as inlined, to ensure + -- that even calls with nonstatic actuals will be inlined. + + Set_Has_Pragma_Inline (Def_Id); + Set_Is_Inlined (Def_Id); + end if; end if; -- Check incorrect use of dynamically tagged expression. This doesn't
reply other threads:[~2021-07-09 12:38 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210709123812.7B34D3AAB465@sourceware.org \ --to=pmderodat@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).