From patchwork Mon May 15 09:41:35 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: 94016 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6790092vqo; Mon, 15 May 2023 02:43:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4jphTljEsKwDckQZkDrCwKg8wZobaqM5ZT0r2wfJV71ptMGNgjuvPyw3l9CJdURjD3lXJf X-Received: by 2002:a17:907:3f2a:b0:931:cd1b:3c0 with SMTP id hq42-20020a1709073f2a00b00931cd1b03c0mr31140380ejc.3.1684143780987; Mon, 15 May 2023 02:43:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684143780; cv=none; d=google.com; s=arc-20160816; b=bMsLuh462G20RTGKG0McOVkwxYDk+21MlLGRAnXprVlqdrzD/7HHvIYFYxSPbF9HIr DvUhH4Cwz+e/DiNuPXKQRIbLQFM1chYK37mTkre8hIHRTieCVLOz4tD8JFygrQUl0K5F hrZVYTM724zufxNJgTan6eqvC7d4Zi0di3flV3hzly5tjnlr9IEppBhdHhkxtcL72PWy MnYUqWMWMagQCWUczLqoN13rfze0aaFDZOFqfTV0YrBGoY6BwSWAOci/hI4GAmbUhgW4 KotxB1IVMvJgYtpYDW8lOwu4PNWvuFEkCHCM+03L+Knm7exsyerCBRjUMISSPLDVCTSD nJ8Q== 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=FfnXH1Z7+c4tNxLkruYXRf9SAYYIbIpti/q02e5FAzM=; b=KQIUoPHEVAfrpf1fziw6hjYUcNhEG3Wb3+ReLyJmcHKB2J88rmrvQdsFCQFQ2Gbsy8 hUcQfFgwWt1CTszok3l17Zn5e0HnIrJtOs1EPjyF+BXwG3D4BS9FDhf7LUkcqdYUS3uJ PZT5i0+dOrJ8aHrm4kLepZmm+QFc8zzMmc3QeYhF7HqC/xrXOZ9NCY0J+hC8UT4RNUZ/ CcK1VihVCEcqWNFkdeMbXxhvltAOlDpcxjjttWHdg+K+kSP0EDktkI8ZyrVuH3F0vlCo zhfuX36iKtUK9Bf/9meY5+ti9epv5Pld+1UXLwF7Q5KYJBgBy09wq5aQMrSZb5+OzoIR sYrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=k3V+ubOR; 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 n20-20020a170906841400b0094f8f46c1b1si12263886ejx.646.2023.05.15.02.43.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 02:43:00 -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=k3V+ubOR; 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 B825A3853558 for ; Mon, 15 May 2023 09:42:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B825A3853558 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684143752; bh=FfnXH1Z7+c4tNxLkruYXRf9SAYYIbIpti/q02e5FAzM=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=k3V+ubOR0C4OeEwrHxC6b+wgrlkDVUSNkruVZN0SYTyswgKgzeshrdJNeaqFNAEtA tVbCwxs8jTg8WNdqZeOUCsNgdrzoYkL5AXtm8trc/J7nu6C58vgYU3kc90RxzVC8bv 9FNB1MNhjdBptMjDzVbCXWzZXUgewgkIMaCOzvZw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 6577B38555A7 for ; Mon, 15 May 2023 09:41:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6577B38555A7 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f50020e0f8so44116465e9.0 for ; Mon, 15 May 2023 02:41:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684143700; x=1686735700; 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=FfnXH1Z7+c4tNxLkruYXRf9SAYYIbIpti/q02e5FAzM=; b=iA5mrJTszdf3GsdjAGQ7xraftopv0I6d1+IawQmKHxh5HQfHBpXFCLj68iYbSHtwER awwKKCBX4iPOpkvV39uBF7X6cjfJSOzDY08M/m/0uspCuDlIVqmb9NtTphlDOPS2sw6y nFreFBq7/CgjxTUzdlBfemMR6PoevqbLhdIW3iTY/USlAXlQzHD5dditnK/t9RJe+Jes AcdX/B0eJT9eXDmqzqk+QWZ1dKYgqDTpMU4NZipPD7qI/1AWm7nknrhwstZDXNK52vSI N9sFqIlvpWFGeDEjUtLv3WgL5IxkFIXnR3xr3+UizAOPvpUoqKK3r/CpEJsqcK6CaeWV yhqw== X-Gm-Message-State: AC+VfDy/PcYboOB0JZtfubKngiPQnsg6YhmI3jMFMeff4XVhvi+G1RQ6 yIFvA3+0g8I955iAzQuvT19bInu+pqzmdj3lbBsS9g== X-Received: by 2002:a5d:4ac9:0:b0:306:2b7d:24c1 with SMTP id y9-20020a5d4ac9000000b003062b7d24c1mr25628605wrs.8.1684143700008; Mon, 15 May 2023 02:41:40 -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 t25-20020a1c7719000000b003f43f82001asm16538951wmi.31.2023.05.15.02.41.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 02:41:39 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Fix link to parent when copying with Copy_Separate_Tree Date: Mon, 15 May 2023 11:41:35 +0200 Message-Id: <20230515094135.1407003-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.0 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?1765952749465354374?= X-GMAIL-MSGID: =?utf-8?q?1765952749465354374?= From: Piotr Trojanek When flag More_Ids is set on a node, then syntactic children will have their Parent link set to the last node in the chain of Mode_Ids. For example, parameter associations in declaration like: procedure P (X, Y : T); will have More_Ids set for "X", Prev_Ids set on "Y" and both will have the same node of "T" as their child. However, "T" will have only one parent, i.e. "Y". This anomaly was taken into account in New_Copy_Tree, but not in Copy_Separate_Tree. This was leading to spurious errors in check for ghost-correctness applied to copied specs. gcc/ada/ * atree.ads (Is_Syntactic_Node): Refactored from New_Copy_Tree. * atree.adb (Is_Syntactic_Node): Likewise. (Copy_Separate_Tree): Use Is_Syntactic_Node. * sem_util.adb (Has_More_Ids): Move to Atree. (Is_Syntactic_Node): Likewise. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/atree.adb | 62 +++++++++++++++++++++++++++++++++++++++++++- gcc/ada/atree.ads | 8 ++++++ gcc/ada/sem_util.adb | 62 ++------------------------------------------ 3 files changed, 71 insertions(+), 61 deletions(-) diff --git a/gcc/ada/atree.adb b/gcc/ada/atree.adb index 6ad8b5d2fa3..669b1bf225d 100644 --- a/gcc/ada/atree.adb +++ b/gcc/ada/atree.adb @@ -1378,7 +1378,7 @@ package body Atree is New_N := Union_Id (Copy_Separate_Tree (Node_Id (Field))); if Present (Node_Id (Field)) - and then Parent (Node_Id (Field)) = Source + and then Is_Syntactic_Node (Source, Node_Id (Field)) then Set_Parent (Node_Id (New_N), New_Id); end if; @@ -1619,6 +1619,66 @@ package body Atree is return Nkind (N) in N_Entity; end Is_Entity; + ----------------------- + -- Is_Syntactic_Node -- + ----------------------- + + function Is_Syntactic_Node + (Source : Node_Id; + Field : Node_Id) + return Boolean + is + function Has_More_Ids (N : Node_Id) return Boolean; + -- Return True when N has attribute More_Ids set to True + + ------------------ + -- Has_More_Ids -- + ------------------ + + function Has_More_Ids (N : Node_Id) return Boolean is + begin + if Nkind (N) in N_Component_Declaration + | N_Discriminant_Specification + | N_Exception_Declaration + | N_Formal_Object_Declaration + | N_Number_Declaration + | N_Object_Declaration + | N_Parameter_Specification + | N_Use_Package_Clause + | N_Use_Type_Clause + then + return More_Ids (N); + else + return False; + end if; + end Has_More_Ids; + + -- Start of processing for Is_Syntactic_Node + + begin + if Parent (Field) = Source then + return True; + + -- Perform the check using the last id in the syntactic chain + + elsif Has_More_Ids (Source) then + declare + N : Node_Id := Source; + + begin + while Present (N) and then More_Ids (N) loop + Next (N); + end loop; + + pragma Assert (Prev_Ids (N)); + return Parent (Field) = N; + end; + + else + return False; + end if; + end Is_Syntactic_Node; + ---------------- -- Initialize -- ---------------- diff --git a/gcc/ada/atree.ads b/gcc/ada/atree.ads index eb1ff90c3ee..50f75cf4d59 100644 --- a/gcc/ada/atree.ads +++ b/gcc/ada/atree.ads @@ -225,6 +225,14 @@ package Atree is pragma Inline (Is_Entity); -- Returns True if N is an entity + function Is_Syntactic_Node + (Source : Node_Id; + Field : Node_Id) + return Boolean; + -- Return True when Field is a syntactic child of node Source. It is called + -- when creating a copy of Source to preserve the Parent link in the copy + -- of Field. + function New_Node (New_Node_Kind : Node_Kind; New_Sloc : Source_Ptr) return Node_Id; diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index f2856353671..5ec0140d090 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -23323,65 +23323,6 @@ package body Sem_Util is New_Par : Node_Id := Empty; Semantic : Boolean := False) return Union_Id is - function Has_More_Ids (N : Node_Id) return Boolean; - -- Return True when N has attribute More_Ids set to True - - function Is_Syntactic_Node return Boolean; - -- Return True when Field is a syntactic node - - ------------------ - -- Has_More_Ids -- - ------------------ - - function Has_More_Ids (N : Node_Id) return Boolean is - begin - if Nkind (N) in N_Component_Declaration - | N_Discriminant_Specification - | N_Exception_Declaration - | N_Formal_Object_Declaration - | N_Number_Declaration - | N_Object_Declaration - | N_Parameter_Specification - | N_Use_Package_Clause - | N_Use_Type_Clause - then - return More_Ids (N); - else - return False; - end if; - end Has_More_Ids; - - ----------------------- - -- Is_Syntactic_Node -- - ----------------------- - - function Is_Syntactic_Node return Boolean is - Old_N : constant Node_Id := Node_Id (Field); - - begin - if Parent (Old_N) = Old_Par then - return True; - - elsif not Has_More_Ids (Old_Par) then - return False; - - -- Perform the check using the last last id in the syntactic chain - - else - declare - N : Node_Id := Old_Par; - - begin - while Present (N) and then More_Ids (N) loop - Next (N); - end loop; - - pragma Assert (Prev_Ids (N)); - return Parent (Old_N) = N; - end; - end if; - end Is_Syntactic_Node; - begin -- The field is empty @@ -23393,7 +23334,8 @@ package body Sem_Util is elsif Field in Node_Range then declare Old_N : constant Node_Id := Node_Id (Field); - Syntactic : constant Boolean := Is_Syntactic_Node; + Syntactic : constant Boolean := + Is_Syntactic_Node (Source => Old_Par, Field => Old_N); New_N : Node_Id;