From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id DF2413858433; Wed, 22 Sep 2021 15:10:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DF2413858433 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-3797] [Ada] Generate temporary for if-expression with -fpreserve-control-flow X-Act-Checkin: gcc X-Git-Author: Eric Botcazou X-Git-Refname: refs/heads/master X-Git-Oldrev: ec813d06f788fed7e0d9f47f77182877f1d8cf47 X-Git-Newrev: 26ece6eca7c02675fcae29a1fa5285b740241d60 Message-Id: <20210922151003.DF2413858433@sourceware.org> Date: Wed, 22 Sep 2021 15:10:03 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Sep 2021 15:10:04 -0000 https://gcc.gnu.org/g:26ece6eca7c02675fcae29a1fa5285b740241d60 commit r12-3797-g26ece6eca7c02675fcae29a1fa5285b740241d60 Author: Eric Botcazou Date: Thu Jul 15 11:18:02 2021 +0200 [Ada] Generate temporary for if-expression with -fpreserve-control-flow gcc/ada/ * exp_ch4.adb (Expand_N_If_Expression): Generate an intermediate temporary when the expression is a condition in an outer decision and control-flow optimizations are suppressed. Diff: --- gcc/ada/exp_ch4.adb | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 497a52ba05d..d7037bf37f2 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -6253,6 +6253,46 @@ package body Exp_Ch4 is return; end if; + -- For the sake of GNATcoverage, generate an intermediate temporary in + -- the case where the if-expression is a condition in an outer decision, + -- in order to make sure that no branch is shared between the decisions. + + elsif Opt.Suppress_Control_Flow_Optimizations + and then Nkind (Original_Node (Parent (N))) in N_Case_Expression + | N_Case_Statement + | N_If_Expression + | N_If_Statement + | N_Goto_When_Statement + | N_Loop_Statement + | N_Return_When_Statement + | N_Short_Circuit + then + declare + Cnn : constant Entity_Id := Make_Temporary (Loc, 'C'); + Acts : List_Id; + + begin + -- Generate: + -- do + -- Cnn : constant Typ := N; + -- in Cnn end + + Acts := New_List ( + Make_Object_Declaration (Loc, + Defining_Identifier => Cnn, + Constant_Present => True, + Object_Definition => New_Occurrence_Of (Typ, Loc), + Expression => Relocate_Node (N))); + + Rewrite (N, + Make_Expression_With_Actions (Loc, + Expression => New_Occurrence_Of (Cnn, Loc), + Actions => Acts)); + + Analyze_And_Resolve (N, Typ); + return; + end; + -- If no actions then no expansion needed, gigi will handle it using the -- same approach as a C conditional expression.