From patchwork Mon Nov 28 12:04:58 2022 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: 26713 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5611750wrr; Mon, 28 Nov 2022 04:06:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf7wQbKSKVM/jw7rT1Xt6dr0VMxVeJAGrq6ZETyc5aQhkOH6iU2BGg2/2lqW4HVeir3VEolD X-Received: by 2002:a17:906:a58:b0:7ad:b45c:dbca with SMTP id x24-20020a1709060a5800b007adb45cdbcamr31998531ejf.388.1669637183006; Mon, 28 Nov 2022 04:06:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669637183; cv=none; d=google.com; s=arc-20160816; b=DZ4l7FU39bqtpDbkslrczo92arKURbHRuixVpvvn0YFTBfHpaFHZUhhL/Tevns9rcO WczZeiz8UheSVhwAzDgBlpAoKEhgtRYGyHkkt7Y7bbhmf3M6Fv2OOgoT1b8fvgsCPmKg W23zqSePwb+e2A0pVhM0IHlGPmBd54Rrzycap3Td2K2z9RaJU0+JLN7n4wrzKK4qnSbZ RGmPo9OAjtgMJtR2gimOVudS9Me6t57DlAPosyVrypO6S8RuuBgRHPiVS2/tFvVRvEN4 vBgVbo3YJfHmj7q7ADWn4+2VEYAidC7RvyFxYN80AtAOjwc0xIBhjuI/4jaVKZbEBYxb 6/yw== 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=Tp7Nt9yt/k6LgK68omlV7dJRBrq/4VnJXJOiktxDOa4=; b=lXhfJdmwIYF7YkWUnx+7tmM2vT3elmTkSN5OcW4xpVEQtUumeWmECgXENaw/D419cG bbNM70j7vI1Hnklzmhe00PYNxFqhGFSg0RVgECdzrPGx1iKFRI8UquJO1iI8c6HRn87B nRI3UsOETbxB3Y7xoUpzZhOoPvcihaWWK+ZhF95CTtVB3oqg1q/UMO413clKWOJMicUy RHO7PGV/YqSxm2ceZjwb9Y7MqUrEXq9e4IQcWsjkhDBzUDp8yPGL5+8ruiotVJSpjdNZ cOxcC+HL3gqelbYagD9T5aw6A5mYOglbtuVXzcO5akrIQ1Z4D3obqqAkduNMRVGA/fxo JeiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TWe8ObuZ; 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 sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fj27-20020a0564022b9b00b0046a7c877f58si8239623edb.335.2022.11.28.04.06.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 04:06:22 -0800 (PST) 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=TWe8ObuZ; 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 ED495384F481 for ; Mon, 28 Nov 2022 12:05:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED495384F481 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669637147; bh=Tp7Nt9yt/k6LgK68omlV7dJRBrq/4VnJXJOiktxDOa4=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=TWe8ObuZ3HGGxMBc4sk6ICfhKeISCVAXuNsVwS4Jw9v9McRwPu+/evB7YekjoIIcz IcZOte0hBVuQlU6mNbrh6UdWB32J0jZn3CErIT9aXf9A63nsRE+vXSwEGaufk8bKIt AK7LBJ6hDmic1DCMeZKXE+sDcVKrI0/oYwBKMQMI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id CD7143858422 for ; Mon, 28 Nov 2022 12:05:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CD7143858422 Received: by mail-wr1-x42f.google.com with SMTP id q7so15543994wrr.8 for ; Mon, 28 Nov 2022 04:05:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Tp7Nt9yt/k6LgK68omlV7dJRBrq/4VnJXJOiktxDOa4=; b=I4ujlWxko0lmOu3a/9+iw0gVFrn+A0njYWvJwDxPbm/TtPRMM3qcyyBJGEJEDxl1IW MY0ClQG87PDSxgLv0RMmIcW7DaM9EwRr95ShWQkKcEerv3sM8+MUVPuZF4xhfkjvaQ5Q s+4bXm/b19QHWTiqQ7wdQG6e7Gc9sfgTYoMudlfPs0KDdcwiL0kSKwDlNbtH+mzaWs6+ NOANijlhJKSkfUhdEwlcg1u0iqGnAt78PIXKUPiXPfKPGssPTNXW4WJ3mtR6i50pJ/tm hvXW4eEx2f0eXHPYhRxKWSMAWe77ZX/YHVUb63g32VYtZYplq0pGJuQGBbE4DbX/rp9l yEDg== X-Gm-Message-State: ANoB5pm3rjQ+aNjKg2eNGuIOvpcGNYts+5E1cffytJpejAcJU02lJUhp w8aSnK5h6afnC0ehHg4SXHpW4yrwjTIycA== X-Received: by 2002:a5d:5602:0:b0:22e:4c41:9e45 with SMTP id l2-20020a5d5602000000b0022e4c419e45mr25132477wrv.468.1669637101548; Mon, 28 Nov 2022 04:05:01 -0800 (PST) Received: from localhost.localdomain (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id i7-20020a05600c354700b003d04e4ed873sm9561467wmq.22.2022.11.28.04.05.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 04:05:01 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix internal error on conversion as in/out actual with -gnatVa Date: Mon, 28 Nov 2022 13:04:58 +0100 Message-Id: <20221128120458.171543-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 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.29 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750741478962182118?= X-GMAIL-MSGID: =?utf-8?q?1750741478962182118?= From: Eric Botcazou The problem is that the regular expansion of the conversion around the call to the subprogram is disabled by the expansion of the validity check around the same call, as documented in Expand_Actuals: -- This case is given higher priority because the subsequent check -- for type conversion may add an extra copy of the variable and -- prevent proper value propagation back in the original object. Now the two mechanisms need to cooperate in order for the code to compile. gcc/ada/ * exp_ch6.adb (Expand_Actuals.Add_Call_By_Copy_Code): Deal with a reference to a validation variable in the actual. (Expand_Actuals.Add_Validation_Call_By_Copy_Code): Minor tweak. (Expand_Actuals): Call Add_Validation_Call_By_Copy_Code directly only if Add_Call_By_Copy_Code is not to be invoked. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch6.adb | 61 ++++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index 237a19d1327..0fe980c499a 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -1639,6 +1639,27 @@ package body Exp_Ch6 is Crep := False; end if; + -- If the actual denotes a variable which captures the value of an + -- object for validation purposes, we propagate the link with this + -- object to the new variable made from the actual just above. + + if Ekind (Formal) /= E_In_Parameter + and then Is_Validation_Variable_Reference (Actual) + then + declare + Ref : constant Node_Id := Unqual_Conv (Actual); + + begin + if Is_Entity_Name (Ref) then + Set_Validated_Object (Var, Validated_Object (Entity (Ref))); + + else + pragma Assert (False); + null; + end if; + end; + end if; + -- Setup initialization for case of in out parameter, or an out -- parameter where the formal is an unconstrained array (in the -- latter case, we have to pass in an object with bounds). @@ -1906,6 +1927,13 @@ package body Exp_Ch6 is Name => Lhs, Expression => Expr)); end if; + + -- Add a copy-back to reflect any potential changes in value + -- back into the original object, if any. + + if Is_Validation_Variable_Reference (Lhs) then + Add_Validation_Call_By_Copy_Code (Lhs); + end if; end; end if; end Add_Call_By_Copy_Code; @@ -2052,10 +2080,11 @@ package body Exp_Ch6 is -------------------------------------- procedure Add_Validation_Call_By_Copy_Code (Act : Node_Id) is + Var : constant Node_Id := Unqual_Conv (Act); + Expr : Node_Id; Obj : Node_Id; Obj_Typ : Entity_Id; - Var : constant Node_Id := Unqual_Conv (Act); Var_Id : Entity_Id; begin @@ -2405,26 +2434,10 @@ package body Exp_Ch6 is end if; end if; - -- The actual denotes a variable which captures the value of an - -- object for validation purposes. Add a copy-back to reflect any - -- potential changes in value back into the original object. - - -- Var : ... := Object; - -- if not Var'Valid then -- validity check - -- Call (Var); -- modify var - -- Object := Var; -- update Object - - -- This case is given higher priority because the subsequent check - -- for type conversion may add an extra copy of the variable and - -- prevent proper value propagation back in the original object. - - if Is_Validation_Variable_Reference (Actual) then - Add_Validation_Call_By_Copy_Code (Actual); - -- If argument is a type conversion for a type that is passed by -- copy, then we must pass the parameter by copy. - elsif Nkind (Actual) = N_Type_Conversion + if Nkind (Actual) = N_Type_Conversion and then (Is_Elementary_Type (E_Formal) or else Is_Bit_Packed_Array (Etype (Formal)) @@ -2508,6 +2521,18 @@ package body Exp_Ch6 is and then not In_Subrange_Of (E_Actual, E_Formal))) then Add_Call_By_Copy_Code; + + -- The actual denotes a variable which captures the value of an + -- object for validation purposes. Add a copy-back to reflect any + -- potential changes in value back into the original object. + + -- Var : ... := Object; + -- if not Var'Valid then -- validity check + -- Call (Var); -- modify var + -- Object := Var; -- update Object + + elsif Is_Validation_Variable_Reference (Actual) then + Add_Validation_Call_By_Copy_Code (Actual); end if; -- RM 3.2.4 (23/3): A predicate is checked on in-out and out