From patchwork Tue Jan 9 13:15:35 2024 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: 186368 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp99803dyi; Tue, 9 Jan 2024 05:18:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFuN6266yf46yCcPxFpPzKyZalhMw0bgYEzzzq8pp/mfA0hOU+Sagk+us5b2HZMqYawfU5L X-Received: by 2002:ac8:5fcc:0:b0:429:9cbc:2a9c with SMTP id k12-20020ac85fcc000000b004299cbc2a9cmr2078927qta.36.1704806335820; Tue, 09 Jan 2024 05:18:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704806335; cv=pass; d=google.com; s=arc-20160816; b=LpRq/KMX4NthMZ+BPU8pVlyS5OECg+7MR499n1yZM4JzZp4cjtF/4N2UMvGhFwwMgp EvmmRqh1z1tlypK+KifoSajVLLv3jQDotUISoWcF+CsdrGfrmKiYcuqD0Msj3VtC5Z5T qQLlzV1RzSXWoWPellVltbxpJ3qSkivfVsVgr85lh8laNO6KyX1VEO7fcpKPOgq4gb1l 7I8zHL01Hot9bOgwgjq9G5OsrNM0XVSsvfN7R9xAjzxyAoSTjJnVCYBN5UCBNUa9JKC3 MMDaFu9Ry6M2p8ReAwIZJhz3pnQ3Kt1zjlPRjP1ylt57rvBoNNLOYrfEYO8M3AZcpMdl Wh7Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=0OqnXOC3V/QnsHmkSkDz9uA3vI/etxk5uH06tR4j7x4=; fh=VfpjIVwbQyKCLGOH4P8eKpbC0rx5s9zOz2f2H065zJg=; b=u3w9Y1bmPDFdkDr5Ta3yEwSD/ASBd5L5KRIx5w5QbFV2Jq1wg/u1mWzVpBs6kay623 HbfrMpSQ4LRWy7iPgyeN19GFlBHSGbpNRPOIivESK7X1EIC/dgDiAWRgthTTXlVuglpz SgvhZoccYhlGJLJx4RVtw6JcAtPyT6runhWZMJzgiCOZ103DXFo8GhuAY1pX5dUAm5uN 2/bn2mn4ecQzWMGKEz6Pr2qOG+dTvixOWEw78KYVVgHujyIwnS9qMN3NCPbuDKujOq7J 1XoNyUSTWvzdpTxOJIengddF12KIKP9JXxmLO6UTgL4LgSspo6D34fVGQE8Re0KwRBlt o8hQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=bheb9x5s; arc=pass (i=1); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n8-20020a05622a11c800b00429a88e5f4bsi931697qtk.567.2024.01.09.05.18.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 05:18:55 -0800 (PST) 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=@adacore.com header.s=google header.b=bheb9x5s; arc=pass (i=1); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AD4113861878 for ; Tue, 9 Jan 2024 13:18:53 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id B9DA83861806 for ; Tue, 9 Jan 2024 13:15:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9DA83861806 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B9DA83861806 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704806145; cv=none; b=aeEVTCP5Js5JEJIuUiUdJM38kugC26Sb9ajPXWaAwbY3n3DJYT4e5GP+G4RI3sGFmNWR2lnoDZ0/alWfhPvezjMsq7wqbeGdMNbEdNMzmWa9v/SUi/5UncdftdgVdEoTANuuxuQ4H02/6XjvmEBeJeKuSlrY/9OazmS32kYaDD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704806145; c=relaxed/simple; bh=BXTnLh7ZP0hcqr1CP9WaPWpmaRf4huGzM7nFqar+nCA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=MhJ3vfmmnPsOyL74DN0JmojbvmcGbw9LasdS7w0NW4Q2+NoYxZKiTozvOC7Jd/3HOTtWurjG7RE+Z2N8gNVyGqdJzVq3DJBxk7byDfkUodsXI5UCprXjMgDjks6VVsheRbM/9livzbxO7nisLwCM1n3owm99x0tho8194Q29w00= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-40e5280a33eso2314785e9.0 for ; Tue, 09 Jan 2024 05:15:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1704806136; x=1705410936; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=0OqnXOC3V/QnsHmkSkDz9uA3vI/etxk5uH06tR4j7x4=; b=bheb9x5sgRtSPSsHq4ls0VnMHBfq/J3NO0a2LodNk9uOxXxuhLzN/gSzLqT9/flbVh iFP83u0sn7fEM6HGyff9Qmkz7Av/fsvZFEImj0B7um4gpO1nlahKF7QsSY+aFbT5mTMz 1yNxj8NKhEEQ3bKPiZw52wey+2HWxTamIuRq/XZ+I7n/ukDMEGg94lEnl4UEgAqqi1TX aBWLHsuyi4QEXxg3NyYijFL0wQ8FbfMjzHGjNyBP9kJPnbf1fU/fAhRfqxhovj/RUl69 fuXq6VSrpARaxkYMgOfYn/3/THTHd6dnUspB9FsFoNuuxwDYfBa9/AQXHl/IBK50Jat9 fC3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704806136; x=1705410936; 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=0OqnXOC3V/QnsHmkSkDz9uA3vI/etxk5uH06tR4j7x4=; b=wEGIGMyP2zefsnEqixQ85B7m0dMhwfXTqeMY2oM9+krTW3bsu3GNRG/h9CVTnDSfe1 V6hHYOx2LzUQonSW8AzNPjRNVbc0ynqTOW+d4pbKAHG5ouF4fA7LyvjVfWTs7Znvx1UF VqlK6FZI1akPUDcUHPVyW7D6qj6CePGcsW+inMbw9Ya179wEN6EM0rMweHTdU2/w+yOp l9RAUDcfizmylQQ9qwJLj725q1RuF8Xhici80J0WL5KzJ+i9Y5wG5zhOd7VdiTPDFUK8 BVrinYi4BjFmUkw76uhUdsBk1Mv8cPpweJrrlCRUZQlm01SU2j9rKsUlqslTa1QMCxLE 0/Kw== X-Gm-Message-State: AOJu0YyWjOtl/1vP2zFx4dVasgppQ5SliU3Uil2lMmv9ZhIIX70GeDE9 UJwUh57rAAzODOKU6mbIL8DF8WZzGoTlI1DupEd2Ul4GVA== X-Received: by 2002:a05:600c:a45:b0:40e:360b:e3e1 with SMTP id c5-20020a05600c0a4500b0040e360be3e1mr414261wmq.13.1704806136497; Tue, 09 Jan 2024 05:15:36 -0800 (PST) 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 u21-20020a05600c00d500b0040e47071200sm2488511wmm.0.2024.01.09.05.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 05:15:36 -0800 (PST) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Steve Baird Subject: [COMMITTED] ada: Fix bug in Sem_Util.Enclosing_Declaration Date: Tue, 9 Jan 2024 14:15:35 +0100 Message-ID: <20240109131535.744072-1-poulhies@adacore.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 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, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787619008230876334 X-GMAIL-MSGID: 1787619008230876334 From: Steve Baird Fix Sem_Util.Enclosing_Declaration to not return an N_Subprogram_Specification node. Remove code in various places that was formerly needed to cope with this misbehavior. gcc/ada/ * sem_util.adb (Enclosing_Declaration): Instead of returning a subprogram specification node, return its parent (which is presumably a subprogram declaration). * contracts.adb (Insert_Stable_Property_Check): Remove code formerly needed to compensate for incorrect behavior of Sem_Util.Enclosing_Declaration. * exp_attr.adb (In_Available_Context): Remove code formerly needed to compensate for incorrect behavior of Sem_Util.Enclosing_Declaration. * sem_ch8.adb (Is_Actual_Subp_Of_Inst): Remove code formerly needed to compensate for incorrect behavior of Sem_Util.Enclosing_Declaration. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/contracts.adb | 12 ++---------- gcc/ada/exp_attr.adb | 11 +---------- gcc/ada/sem_ch8.adb | 10 ---------- gcc/ada/sem_util.adb | 5 +++++ 4 files changed, 8 insertions(+), 30 deletions(-) diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb index fa0d59a246a..21bbbf1219e 100644 --- a/gcc/ada/contracts.adb +++ b/gcc/ada/contracts.adb @@ -2529,17 +2529,9 @@ package body Contracts is Pragma_Argument_Associations => Args, Class_Present => Class_Present); - Subp_Decl : Node_Id := Subp_Id; + Subp_Decl : constant Node_Id := Enclosing_Declaration (Subp_Id); + pragma Assert (Is_Declaration (Subp_Decl)); begin - -- Enclosing_Declaration may return, for example, - -- a N_Procedure_Specification node. Cope with this. - loop - Subp_Decl := Enclosing_Declaration (Subp_Decl); - exit when Is_Declaration (Subp_Decl); - Subp_Decl := Parent (Subp_Decl); - pragma Assert (Present (Subp_Decl)); - end loop; - Insert_After_And_Analyze (Subp_Decl, Prag); end Insert_Stable_Property_Check; diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb index 66fd6848a1d..a781f93c4ef 100644 --- a/gcc/ada/exp_attr.adb +++ b/gcc/ada/exp_attr.adb @@ -8653,17 +8653,8 @@ package body Exp_Attr is -------------------------- function In_Available_Context (Ent : Entity_Id) return Boolean is - Decl : Node_Id := Enclosing_Declaration (Ent); + Decl : constant Node_Id := Enclosing_Declaration (Ent); begin - -- Enclosing_Declaration does not always return a declaration; - -- cope with this irregularity. - if Decl in N_Subprogram_Specification_Id - and then Nkind (Parent (Decl)) in - N_Subprogram_Body | N_Subprogram_Declaration - then - Decl := Parent (Decl); - end if; - if Has_Declarations (Parent (Decl)) then return In_Subtree (Attr_Ref, Root => Parent (Decl)); elsif Is_List_Member (Decl) then diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb index 5408be3e1a5..fc2fec5f224 100644 --- a/gcc/ada/sem_ch8.adb +++ b/gcc/ada/sem_ch8.adb @@ -6562,16 +6562,6 @@ package body Sem_Ch8 is Decl := Enclosing_Declaration (E); - -- Enclosing_Declaration does not always return a - -- declaration; cope with this irregularity. - if Decl in N_Subprogram_Specification_Id - and then Nkind (Parent (Decl)) in - N_Subprogram_Body | N_Subprogram_Declaration - | N_Subprogram_Renaming_Declaration - then - Decl := Parent (Decl); - end if; - -- Look for the suprogram renaming declaration built -- for a generic actual subprogram. Unclear why -- Original_Node call is needed, but sometimes it is. diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 9cff9e1be16..01be86cb41f 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -7386,6 +7386,11 @@ package body Sem_Util is Decl := Parent (Decl); end loop; + -- cope with oddness in definition of N_Declaration + if Nkind (Decl) in N_Subprogram_Specification then + Decl := Parent (Decl); + end if; + return Decl; end Enclosing_Declaration;