From patchwork Thu May 25 08:05:47 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: 98857 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp199462vqr; Thu, 25 May 2023 01:18:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7PEljnVOpL0e8upUx29sgvniYfR747Gdn/fW+QJt7/DkU15U6WnHaiTINAVfzcQox/Y0Bl X-Received: by 2002:a17:907:961b:b0:94a:5d5c:fe6f with SMTP id gb27-20020a170907961b00b0094a5d5cfe6fmr851464ejc.47.1685002707572; Thu, 25 May 2023 01:18:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685002707; cv=none; d=google.com; s=arc-20160816; b=mBHQaDllZ4AbO7NgPthRgNS/P3u/nHo8BUan57eZySkx+EIMXguvlM1czY2JWsyum/ vKbX528Hiae2imPih8IpC+ZThnHzuyJ8AEWq8s9EJKdUAq5RBOCFVM4fk2iOdunD+K1t auRkXHajn5FSNvXwhS5uYQYKq2f8sBVJxNlfgXcUdn5JcJmqGcaGJdZYPLaDWVulnIid rUD47HhDLufuY0/lBgRiTiHT2N5QwUNqqNIxxqm8tckOxsWXH3bUwrS6P1W3JhM4FdjM kgu5C4MVcHXAFy6Q9pTjpVOcq5fIS3rhS7f/q+dDnWj+OMYYZIwXKPz4Gomo2pNikCHj Zeig== 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=bkK8U8090RzbfF0bi4rpb3fE3hMp6IhvlBvFMao2HQs=; b=B0xBYSgP1raT0LZ34gN/o5ZXtWIHnIZ6vlOqmax2LVLJKHQQBvzU9aoX5XHrKO/an0 NPJEvHMVo1JfjzkfFW4IClDNAHtmOnudgU2SjTyyaEkKr1wev14zhP2YUfJYoh7L4Y6T GVfQhkYJpEKaA6gqDfcuoymkpfDLhEgpLxOE4TvHOmQyGzQQC5+ylqiyEwdbNxFxp2zb TU582Dx/hdsofysOL3jmj5Pi6QNtUiolBSKNPoVWR4XYn2zHcIoCKiregc1TFKIui9+e i4yhgfH7IBq/BWT5GES05xr1yJlFZjj7fpyb2EdFMY+NYoseoWzMe9RTzOte/rYFtEQC g3uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=w8g9twak; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id si2-20020a170906cec200b0096627b22c3bsi701843ejb.605.2023.05.25.01.18.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 01:18:27 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=w8g9twak; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 8B57C3954406 for ; Thu, 25 May 2023 08:12:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B57C3954406 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685002337; bh=bkK8U8090RzbfF0bi4rpb3fE3hMp6IhvlBvFMao2HQs=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=w8g9twakUTz3HSakzR8V8IuQUMI/b3A7OPI/l+syjgi3LfxVmdoeE4gMcgUxvlZJf eqShEL/qIoZO/LjCPC29plk/vA8oEdF3W+vDkZFCIqTn+7kacS640lXAOFqboc1WWr nLH5bgOIdotGdfLVpQskqvLQWYMe2ActimqbJK9k= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 3A5C8385735D for ; Thu, 25 May 2023 08:05:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A5C8385735D Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3f6094cb2d2so2920515e9.2 for ; Thu, 25 May 2023 01:05:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685001949; x=1687593949; 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=bkK8U8090RzbfF0bi4rpb3fE3hMp6IhvlBvFMao2HQs=; b=RBLaMb6rPwi7LJH9pnwjYGbn/kCCldjCp5N4X2nEKGst0MBdl93IPVAGuCHBOKpNea mw2NxxMeKNiYft/geA5irWzRHOoYydEULEP+IuSgAizLpDT9RRxY022DD3zmoXbFrwKI m8DPytbaa7QLSSrTgu6AMu3q8XYs9xw2LZW+fMNyvNrAyKEjflFDFY0fmt1+i1FsSrVj egRCGJVAvH6mmz5aXP6TN8elif7GTJfVVuNRnVCBUauPKksEmEVoa+kWWCVDCpsPAhsV S4Up/7W+nwMgtsxlNIFLRKdCWsuGQsL5jC9Rx4YzIST25O3Cj6zENr3lvQ20eYfy5TJ2 tTmA== X-Gm-Message-State: AC+VfDwDVgJ2wzIKH8V/iBPGHDRjWE3+b1wnE5G2UjWcWfdKvNCj04/i ZdbKHFmsu9zvuRxV7FL4v+d4IWxP3X6JBR/w02snpA== X-Received: by 2002:a05:600c:d1:b0:3f2:48dc:5e02 with SMTP id u17-20020a05600c00d100b003f248dc5e02mr1679953wmm.27.1685001948841; Thu, 25 May 2023 01:05:48 -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 e7-20020a056000194700b00307bc4e39e5sm838788wry.117.2023.05.25.01.05.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 01:05:48 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Tune handling of attributes Old in contract Exceptional_Cases Date: Thu, 25 May 2023 10:05:47 +0200 Message-Id: <20230525080547.1956409-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.2 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-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?1766853399426746889?= X-GMAIL-MSGID: =?utf-8?q?1766853399426746889?= From: Piotr Trojanek Contract Exceptional_Cases allows formal parameters to appear *in* prefixes of attributes Old, but the code only allowed them to appear *as* prefixes of those attributes. For example, we now accetp expressions like "X.all'Old" that were previously rejected. gcc/ada/ * sem_res.adb (Resolve_Entity_Name): Tune handling of formal parameters in contract Exceptional_Cases. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_res.adb | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index 17228689364..9161218a32b 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -7832,6 +7832,9 @@ package body Sem_Res is -- Determine whether Expr is part of an N_Attribute_Reference -- expression. + function In_Attribute_Old (Expr : Node_Id) return Boolean; + -- Determine whether Expr is in attribute Old + function Within_Exceptional_Cases_Consequence (Expr : Node_Id) return Boolean; @@ -7878,6 +7881,31 @@ package body Sem_Res is end if; end Is_Assignment_Or_Object_Expression; + ---------------------- + -- In_Attribute_Old -- + ---------------------- + + function In_Attribute_Old (Expr : Node_Id) return Boolean is + N : Node_Id := Expr; + begin + while Present (N) loop + if Nkind (N) = N_Attribute_Reference + and then Attribute_Name (N) = Name_Old + then + return True; + + -- Prevent the search from going too far + + elsif Is_Body_Or_Package_Declaration (N) then + return False; + end if; + + N := Parent (N); + end loop; + + return False; + end In_Attribute_Old; + ----------------------------- -- Is_Attribute_Expression -- ----------------------------- @@ -8080,12 +8108,12 @@ package body Sem_Res is -- Parameters of modes OUT or IN OUT of the subprogram shall not -- occur in the consequences of an exceptional contract unless - -- they either are of a by-reference type or occur in the prefix + -- they are either passed by reference or occur in the prefix -- of a reference to the 'Old attribute. if Ekind (E) in E_Out_Parameter | E_In_Out_Parameter and then Within_Exceptional_Cases_Consequence (N) - and then not Is_Attribute_Old (Parent (N)) + and then not In_Attribute_Old (N) and then not Is_By_Reference_Type (Etype (E)) and then not Is_Aliased (E) then