From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id 0215A3856DE0 for ; Mon, 4 Jul 2022 07:50:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0215A3856DE0 Received: by mail-ej1-x62e.google.com with SMTP id g26so15244491ejb.5 for ; Mon, 04 Jul 2022 00:50:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=E4BNe/kfxcRgjQ0zOZIjE9ptIZdxZr/o/3bn9GcruRE=; b=KHL0YZeRmqwD7GIuy0gAD13fCUSHUfm1mHQ+7qxXdZUuCOdrFAgTyGFlM+y9WW11ec 1MF2AQqueCCEw9STJpK8Xs3N3qSC5GWigx5+XBSj/9wVyBUZza6QBbIcrcbUiWhrfrgP GHMln763eABCaVxjKFefRwfqG72lG6Js8pnc/ZXSLGVlm49rmc64p7RA3cnMp790lp+R oRbr4QMTqmwuC3xaMZkPH9cMUndf9D3lVbogTfDC+lBz6mdIDSlS9ZjaY/gtrbYuwazA AH0ejnIArqNoJqrSn5rd91dgQOy2dpZ9inH3BKQPNZIcvaCTNE5vHg3sx65/WMtd/IAN tVcQ== X-Gm-Message-State: AJIora+tQU8GOTv1tZeRAhRk75E2dUI0hscCV8mxMzK8Z3kAA1q9b+UY DUgpVLmBA2oCb79Hyxj7wYYAgwCMMsmnlw== X-Google-Smtp-Source: AGRyM1vave0r8/KRDYsKc9ddMklaQgcYhrKbrvtjzrCgibVcrZ7IcZWYoHpd4sJ5+48U52vszSHSPQ== X-Received: by 2002:a17:907:1c8a:b0:6e9:2a0d:d7b7 with SMTP id nb10-20020a1709071c8a00b006e92a0dd7b7mr25856179ejc.572.1656921017589; Mon, 04 Jul 2022 00:50:17 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id da26-20020a056402177a00b004359a690905sm20540409edb.78.2022.07.04.00.50.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 00:50:17 -0700 (PDT) Date: Mon, 4 Jul 2022 07:50:16 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [Ada] Do not use front-end build-in-place mechanism for nonlimited types Message-ID: <20220704075016.GA99175@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="a8Wt8u1KmwUX3Y2C" Content-Disposition: inline X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jul 2022 07:50:20 -0000 --a8Wt8u1KmwUX3Y2C Content-Type: text/plain; charset=us-ascii Content-Disposition: inline It was only used in specific cases for controlled types but no longer provides any significant benefit in practice. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * debug.adb (d.9): Remove usage. * exp_ch6.adb (Expand_Simple_Function_Return): Remove redundant test on Debug_Flag_Dot_L. (Is_Build_In_Place_Result_Type): Return false for nonlimited types. (Is_Build_In_Place_Function): Tidy up and remove redundant test on Debug_Flag_Dot_L. --a8Wt8u1KmwUX3Y2C Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/debug.adb b/gcc/ada/debug.adb --- a/gcc/ada/debug.adb +++ b/gcc/ada/debug.adb @@ -211,7 +211,7 @@ package body Debug is -- d.6 Do not avoid declaring unreferenced types in C code -- d.7 Disable unsound heuristics in gnat2scil (for CP as SPARK prover) -- d.8 Disable unconditional inlining of expression functions - -- d.9 Disable build-in-place for nonlimited types + -- d.9 -- d_1 -- d_2 @@ -1125,9 +1125,6 @@ package body Debug is -- This debug flag turns off this behavior, making them subject -- to the usual inlining heuristics of the code generator. - -- d.9 Disable build-in-place for function calls returning nonlimited - -- types. - ------------------------------------------ -- Documentation for Binder Debug Flags -- ------------------------------------------ diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -7252,7 +7252,6 @@ package body Exp_Ch6 is if not Comes_From_Extended_Return_Statement (N) and then Is_Build_In_Place_Function (Scope_Id) - and then not Debug_Flag_Dot_L -- The functionality of interface thunks is simple and it is always -- handled by means of simple return statements. This leaves their @@ -8534,72 +8533,9 @@ package body Exp_Ch6 is -- of a function with a limited interface result, where the function -- may return objects of nonlimited descendants. - if Is_Limited_View (Typ) then - return Ada_Version >= Ada_2005 and then not Debug_Flag_Dot_L; - - else - if Debug_Flag_Dot_9 then - return False; - end if; - - if Has_Interfaces (Typ) then - return False; - end if; - - declare - T : Entity_Id := Typ; - begin - -- For T'Class, return True if it's True for T. This is necessary - -- because a class-wide function might say "return F (...)", where - -- F returns the corresponding specific type. We need a loop in - -- case T is a subtype of a class-wide type. - - while Is_Class_Wide_Type (T) loop - T := Etype (T); - end loop; - - -- If this is a generic formal type in an instance, return True if - -- it's True for the generic actual type. - - if Nkind (Parent (T)) = N_Subtype_Declaration - and then Present (Generic_Parent_Type (Parent (T))) - then - T := Entity (Subtype_Indication (Parent (T))); - - if Present (Full_View (T)) then - T := Full_View (T); - end if; - end if; - - if Present (Underlying_Type (T)) then - T := Underlying_Type (T); - end if; - - declare - Result : Boolean; - -- So we can stop here in the debugger - begin - -- ???For now, enable build-in-place for a very narrow set of - -- controlled types. Change "if True" to "if False" to - -- experiment with more controlled types. Eventually, we might - -- like to enable build-in-place for all tagged types, all - -- types that need finalization, and all caller-unknown-size - -- types. - - if True then - Result := Is_Controlled (T) - and then not Is_Generic_Actual_Type (T) - and then Present (Enclosing_Subprogram (T)) - and then not Is_Compilation_Unit (Enclosing_Subprogram (T)) - and then Ekind (Enclosing_Subprogram (T)) = E_Procedure; - else - Result := Is_Controlled (T); - end if; - - return Result; - end; - end; - end if; + return Is_Limited_View (Typ) + and then Ada_Version >= Ada_2005 + and then not Debug_Flag_Dot_L; end Is_Build_In_Place_Result_Type; ------------------------------ @@ -8635,6 +8571,9 @@ package body Exp_Ch6 is -------------------------------- function Is_Build_In_Place_Function (E : Entity_Id) return Boolean is + Kind : constant Entity_Kind := Ekind (E); + Typ : constant Entity_Id := Etype (E); + begin -- This function is called from Expand_Subtype_From_Expr during -- semantic analysis, even when expansion is off. In those cases @@ -8644,22 +8583,16 @@ package body Exp_Ch6 is return False; end if; - if Ekind (E) in E_Function | E_Generic_Function - or else (Ekind (E) = E_Subprogram_Type - and then Etype (E) /= Standard_Void_Type) - then - -- If the function is imported from a foreign language, we don't do - -- build-in-place. Note that Import (Ada) functions can do - -- build-in-place. Note that it is OK for a build-in-place function - -- to return a type with a foreign convention; the build-in-place - -- machinery will ensure there is no copying. - - return Is_Build_In_Place_Result_Type (Etype (E)) - and then not (Has_Foreign_Convention (E) and then Is_Imported (E)) - and then not Debug_Flag_Dot_L; - else - return False; - end if; + -- If the function is imported from a foreign language, we don't do + -- build-in-place, whereas Import (Ada) functions can do it. Note also + -- that it is OK for a build-in-place function to return a type with a + -- foreign convention because the machinery ensures there is no copying. + + return (Kind in E_Function | E_Generic_Function + or else + (Kind = E_Subprogram_Type and then Typ /= Standard_Void_Type)) + and then Is_Build_In_Place_Result_Type (Typ) + and then not (Is_Imported (E) and then Has_Foreign_Convention (E)); end Is_Build_In_Place_Function; ------------------------------------- --a8Wt8u1KmwUX3Y2C--