From patchwork Thu Sep 14 12:46:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 139563 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp321226vqi; Thu, 14 Sep 2023 05:47:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCxwHXXa+OiOma/ff2zfLmyMlK+Y+bC2uu8ThZk0kgxQVb2H/+dv6aNpKK8cD38Sed07zn X-Received: by 2002:a5d:6a4c:0:b0:31f:af30:1bd9 with SMTP id t12-20020a5d6a4c000000b0031faf301bd9mr4549668wrw.44.1694695663790; Thu, 14 Sep 2023 05:47:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694695663; cv=none; d=google.com; s=arc-20160816; b=kuW2OWte9rP3pkPgKCtQEHUoK+0NTnjVACCP4/quZe9Ai7pZ9cLnaGM++PMjUA/4zt yAoX+Ra8/dsduD0l4u9aLhR4sSJoqu/vvK5JWuq0P0sTGXiL+MSWumVkgS/s4zHDNAvw v4gXYW64F74obbkwb61+hhg3YOtRXjJ0Y6h7VDpyiY2RWKn92/f+DJTUb7mEDIHFuyBw ULCjD+hYcPuZsspj8/dorohgjjITHF3B2QxiCgF7iawP5NKOewYs5vMSnsK4uRu6/LHP NYnu2MWC7w8+VOZF+VqIL2uswwaZtua1JXzpDcAedEPTrJyJyRdvSZXY/eLsX9jt2Whk kCXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=UGH1USWiON/DUdT+mxQBxfvY4DHtFGO8Wl1x5k6hK/A=; fh=hOhsC1930eHatDPYd2EALQ9Ry/g++vvN4vxlQkRuX+0=; b=CZuiO4iahjWd5qc0TPIVQbLIa12E7ZVjFQOaI/FFkBZ5csCEu784QixDuYPRigz3KA VwGPI9rgsaabrf2K27sWfQBkEYiWNll7TZen2/MaJ7AiI6aoZ2PoqrZtbLnxm8Y6eoy7 wAVxvm3qXEVR1CaCnvQ+sdlCtaWuSxa0npOKbMRoctI3WpgUKhTtVOxf18icV1GKNFDj dTdFNtbZHfVTplzIHgL9u4RAn/bXJSS4rcb6Q5Y9+GPf1RYu9+rSr32rbEsJ1U04t/wH VASCRJf/9uJBWgAgkcA4qmcBxGGYzWmVITl7HEnjnN60C2TgHpTUVQf11Ypbqynl3PvV nMXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BwVCujic; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r24-20020aa7da18000000b00529fac9631bsi1306279eds.341.2023.09.14.05.47.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 05:47:43 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BwVCujic; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BDFCD385CC82 for ; Thu, 14 Sep 2023 12:46:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BDFCD385CC82 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694695615; bh=UGH1USWiON/DUdT+mxQBxfvY4DHtFGO8Wl1x5k6hK/A=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=BwVCujicyGPhmuEvCXOaqZgVk+x9dxntbpn8NCFTS2pDSP8u4hYzpaqMANGSSaU2G dBPZ5uyxfp4XR6tnpIiSuQckSXUAi8pSjI9D9XvHKKl17ByGdsTO9GdXXtxStr5Ct0 CayrAWXtVbxWe8k9GoffxzL8Q3e9FGfcu9eYlIug= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 6B4D33858C2B for ; Thu, 14 Sep 2023 12:46:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B4D33858C2B Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-31f7400cb74so747562f8f.2 for ; Thu, 14 Sep 2023 05:46:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694695569; x=1695300369; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UGH1USWiON/DUdT+mxQBxfvY4DHtFGO8Wl1x5k6hK/A=; b=u9sF3BJ+wDlsmCpOeOClraVWmrNCWcMrO3+9jYnE52hxv3p+2ci6KF5MlQXK1ofliV Dvj2Jjc5iMWE8PpcGeAW5OVMGz4Gm7exlrMNVogNZVMkRKhk8x4ZImNtYmScZL+rd7io qNh/3H38016LJAvmjmR0MR02zsQ3vPqU6tN6VeHm7OTJ+W/2Am04PRSwSrSk/pn0V/BY ezwniTZUA5imV5t1sWtxR5moL/+d1lTlbJWFJjdzxNaQh94PBUE/Z2oTqDgPRzFV0eXd 9gDOBTeSluKnVpI37lyWwXpBeyeNaHLteKXJocR5G+L2mVvuIxzJvkkK2XQhg/OiRuBE tC/g== X-Gm-Message-State: AOJu0Ywk5SVVh3E4uLg1zxSB7AZlgD9yoVThGBBdLnbWjb7J6DFv+IU5 RQd/Kfn5lrA1TDl/J+t8fUhvrRKVDsw8ka1Y+seu3g== X-Received: by 2002:a5d:688a:0:b0:31c:70b0:426b with SMTP id h10-20020a5d688a000000b0031c70b0426bmr4885880wru.63.1694695569271; Thu, 14 Sep 2023 05:46:09 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id j6-20020adfff86000000b0031c56218984sm1662159wrr.104.2023.09.14.05.46.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 05:46:08 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix premature finalization in loop over limited iterable container Date: Thu, 14 Sep 2023 14:46:08 +0200 Message-Id: <20230914124608.1950944-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777017200639987771 X-GMAIL-MSGID: 1777017200639987771 From: Eric Botcazou This happens when the iterable container is obtained as the result of a call to a function that is a subprogram parameter of a generic construct. gcc/ada/ * exp_util.adb (Initialized_By_Aliased_BIP_Func_Call): Make the name matching more robust. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_util.adb | 88 ++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb index a4b5ec366f3..0dafa1cd6be 100644 --- a/gcc/ada/exp_util.adb +++ b/gcc/ada/exp_util.adb @@ -8399,65 +8399,73 @@ package body Exp_Util is Call := Unqual_Conv (Call); + -- We search for a formal with a matching suffix. We can't search + -- for the full name, because of the code at the end of Sem_Ch6.- + -- Create_Extra_Formals, which copies the Extra_Formals over to + -- the Alias of an instance, which will cause the formals to have + -- "incorrect" names. See also Exp_Ch6.Build_In_Place_Formal. + if Is_Build_In_Place_Function_Call (Call) then declare Caller_Allocation_Val : constant Uint := UI_From_Int (BIP_Allocation_Form'Pos (Caller_Allocation)); + Access_Suffix : constant String := + BIP_Formal_Suffix (BIP_Object_Access); + Alloc_Suffix : constant String := + BIP_Formal_Suffix (BIP_Alloc_Form); + + function Has_Suffix (Name, Suffix : String) return Boolean; + -- Return True if Name has suffix Suffix + + ---------------- + -- Has_Suffix -- + ---------------- + + function Has_Suffix (Name, Suffix : String) return Boolean is + Len : constant Natural := Suffix'Length; + + begin + return Name'Length > Len + and then Name (Name'Last - Len + 1 .. Name'Last) = Suffix; + end Has_Suffix; - Access_Nam : Name_Id := No_Name; Access_OK : Boolean := False; - Actual : Node_Id; - Alloc_Nam : Name_Id := No_Name; Alloc_OK : Boolean := True; - Formal : Node_Id; - Func_Id : Entity_Id; Param : Node_Id; begin -- Examine all parameter associations of the function call Param := First (Parameter_Associations (Call)); + while Present (Param) loop if Nkind (Param) = N_Parameter_Association and then Nkind (Selector_Name (Param)) = N_Identifier then - Actual := Explicit_Actual_Parameter (Param); - Formal := Selector_Name (Param); - - -- Construct the names of formals BIPaccess and BIPalloc - -- using the function name retrieved from an arbitrary - -- formal. - - if Access_Nam = No_Name - and then Alloc_Nam = No_Name - and then Present (Entity (Formal)) - then - Func_Id := Scope (Entity (Formal)); - - Access_Nam := - New_External_Name (Chars (Func_Id), - BIP_Formal_Suffix (BIP_Object_Access)); - - Alloc_Nam := - New_External_Name (Chars (Func_Id), - BIP_Formal_Suffix (BIP_Alloc_Form)); - end if; + declare + Actual : constant Node_Id + := Explicit_Actual_Parameter (Param); + Formal : constant Node_Id + := Selector_Name (Param); + Name : constant String + := Get_Name_String (Chars (Formal)); - -- A nonnull BIPaccess has been found + begin + -- A nonnull BIPaccess has been found - if Chars (Formal) = Access_Nam - and then Nkind (Actual) /= N_Null - then - Access_OK := True; - end if; + if Has_Suffix (Name, Access_Suffix) + and then Nkind (Actual) /= N_Null + then + Access_OK := True; - -- A BIPalloc has been found + -- A BIPalloc has been found - if Chars (Formal) = Alloc_Nam - and then Nkind (Actual) = N_Integer_Literal - then - Alloc_OK := Intval (Actual) = Caller_Allocation_Val; - end if; + elsif Has_Suffix (Name, Alloc_Suffix) + and then Nkind (Actual) = N_Integer_Literal + then + Alloc_OK := Intval (Actual) = Caller_Allocation_Val; + end if; + end; end if; Next (Param); @@ -8674,7 +8682,7 @@ package body Exp_Util is -- first parameter is the transient. Such a call appears as: -- It : Access_To_Constant_Reference_Type := - -- Constant_Indexing (Tran_Id.all, ...)'reference; + -- Constant_Indexing (Trans_Id.all, ...)'reference; Stmt := First_Stmt; while Present (Stmt) loop @@ -8759,7 +8767,7 @@ package body Exp_Util is -- first parameter is the transient. Such a call appears as: -- It : Access_To_CW_Iterator := - -- Iterate (Tran_Id.all, ...)'reference; + -- Iterate (Trans_Id.all, ...)'reference; Stmt := First_Stmt; while Present (Stmt) loop