From patchwork Fri May 26 07:37:01 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: 99380 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp296322vqr; Fri, 26 May 2023 00:57:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4CpXkNXysy6T3fUAU9nt8m29q+wlO77QBC2Zt+59jg6c5FnRsWu4aWWoV7zEPg9iyMPXuH X-Received: by 2002:a17:907:1c9f:b0:96f:e2c4:a063 with SMTP id nb31-20020a1709071c9f00b0096fe2c4a063mr1348828ejc.33.1685087832388; Fri, 26 May 2023 00:57:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685087832; cv=none; d=google.com; s=arc-20160816; b=dF/hVcLSlpS3+sS3HRMJLKHDXRUEiNgwbo6aVgsxr7Do6jA0fCQCXzGb06vnnfEp24 nJSSgGlKY8czrcJ34qJWBcgDc6JsRKca0gGosGTrgLefqn98OKwmnCrEz894acziclsH AagVvznuYiK2XLQg4H6svrfWFjoC51Jo1ahXJ1DTYOEhYNnHzaVwtMX7IvPm+ck2fpez 39OUuaLNJ9ragYXeNcycF2kKKq7CblvhTL6nFncSeHjjXr0so7ZM/OizEQSCRQOH8OLh FyjClv4KB+ahDUq8cLIT35LKeKOIHpK0xVhuOvKvFszf7Web3dGU1vk9E48zTg8/pmkl TwbA== 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=jJAgF0CWy9rquf+i27S/rYNS2KUZQMciyXujAVS0Fpo=; b=L9YjOHpwASWWql0T5HFzzh/A9vKOTUWf74XxAEilgDVRhHVfpGuo7btZ6kpKkW8Fje Gj/uRONJKt4VHqgFJ/Azj7PqmeN2gTfME40pNu4Q9y5gPqQ6t0sg1lv4oCeTpgqH1rvX nyxM91UAz4PTKb/0sLYBGGCHs5RFJFJUnwyLv+YujU5N3yRzeJIWM7TY0uZ+Taa5sPIu SwbRAlrxPCLpc/oJtzVOlxakhVQmheSfq5Gn0AtSl78Co/heRUiztRKyVtpARbEdorIV FU42YTERYCxbVL7Oi/Ys1CCeOg/o50DmRvRGViwTqevahp2cB8E8r8HUNFHQKrqmPtBm 6aWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dXtmVzYE; 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 vc9-20020a170907d08900b0094f00990945si373045ejc.13.2023.05.26.00.57.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 00:57:12 -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=dXtmVzYE; 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 500AB38395D7 for ; Fri, 26 May 2023 07:45:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 500AB38395D7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685087122; bh=jJAgF0CWy9rquf+i27S/rYNS2KUZQMciyXujAVS0Fpo=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=dXtmVzYEhHTkC7LpjoPwvvFZpn8iwP8URq8qAjZNyjfU/3watDXl5cNs6ksef5UJ4 FZ5wkvAYsFWKO4+kPwULGvoP8NlmFWfyaK7rsZBZHULmw6jK4dBgKvYt0sbf5FANwf GT4nC6j7gKIgm2o3+eIcfaCvkLLybV/pTsYCz0vA= 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 8802E3839DED for ; Fri, 26 May 2023 07:37:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8802E3839DED Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3078d1c8828so342344f8f.3 for ; Fri, 26 May 2023 00:37:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685086623; x=1687678623; 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=jJAgF0CWy9rquf+i27S/rYNS2KUZQMciyXujAVS0Fpo=; b=KM72VmBpQOpWWSh9au9ZSGSOXjavHzXbO8iPZy7Ri6Ca9d2eV2JI0VwbgUbMiHkD08 UzucDOeV9wsZUmjT+VKk2G3SSJEqn3dsg0rFrti2aCbeP6Ajl6Pfuneu8SEvQ9NjgPpH yBwKe6iJZq0SiY/uM1xxEv5TnyyR7AxnX7Z+NAQcVtV8nXLwZ5zyPgKRJX+VpqzNSTH7 AQdHVsBkQhdiORyYe0RM8VKtqkeWA0lxgXsuiB5dYLC/NAjvDmRtCCJxt0xGLszlNAEf IdvCM5KvzWEg2QWo3iNf1rAFK7QcQFIULaJQ0z2U/d8dW7scoW1ckawn/wqGr/reIvIk YU0A== X-Gm-Message-State: AC+VfDxloLmtOS9u9c8BhNQSN62bgVVlEnmf2Ex0IuWnCvkHNHoJYgae WKNOWgQuk8nYWKgbeA5QVgUuFZD8DneLZNoXFYWd/g== X-Received: by 2002:adf:e792:0:b0:309:4368:a8a0 with SMTP id n18-20020adfe792000000b003094368a8a0mr677094wrm.68.1685086623384; Fri, 26 May 2023 00:37:03 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:777b:eef4:6f79:f26f]) by smtp.gmail.com with ESMTPSA id h3-20020a5d5483000000b00307c46f4f08sm1512306wrv.79.2023.05.26.00.37.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 00:37:02 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [COMMITTED] ada: Corrections to premature-references rules Date: Fri, 26 May 2023 09:37:01 +0200 Message-Id: <20230526073701.2070098-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.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.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?1766942659105832766?= X-GMAIL-MSGID: =?utf-8?q?1766942659105832766?= From: Bob Duff This patch corrects the implementation of RM-8.3(17), which says that a record extension is self-hidden until "record". Previously, such premature references could cause a compiler crash. gcc/ada/ * sem_ch3.adb (Build_Derived_Record_Type): Temporarily set the state of the Derived_Type to "self-hidden" while processing constraints and discriminants of a record extension. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch3.adb | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index ff52e05324c..634b1cb4a38 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -9206,10 +9206,14 @@ package body Sem_Ch3 is then -- First, we must analyze the constraint (see comment in point 5.) -- The constraint may come from the subtype indication of the full - -- declaration. + -- declaration. Temporarily set the state of the Derived_Type to + -- "self-hidden" (see RM-8.3(17)). if Constraint_Present then + pragma Assert (Is_Not_Self_Hidden (Derived_Type)); + Set_Is_Not_Self_Hidden (Derived_Type, False); New_Discrs := Build_Discriminant_Constraints (Parent_Type, Indic); + Set_Is_Not_Self_Hidden (Derived_Type); -- If there is no explicit constraint, there might be one that is -- inherited from a constrained parent type. In that case verify that @@ -9507,11 +9511,19 @@ package body Sem_Ch3 is if Discriminant_Specs then Set_Has_Unknown_Discriminants (Derived_Type, False); - -- The following call initializes fields Has_Discriminants and - -- Discriminant_Constraint, unless we are processing the completion - -- of a private type declaration. + -- The following call to Check_Or_Process_Discriminants initializes + -- fields Has_Discriminants and Discriminant_Constraint, unless we + -- are processing the completion of a private type declaration. + -- Temporarily set the state of the Derived_Type to "self-hidden" + -- (see RM-8.3(17)), unless it is already the case. - Check_Or_Process_Discriminants (N, Derived_Type); + if Is_Not_Self_Hidden (Derived_Type) then + Set_Is_Not_Self_Hidden (Derived_Type, False); + Check_Or_Process_Discriminants (N, Derived_Type); + Set_Is_Not_Self_Hidden (Derived_Type); + else + Check_Or_Process_Discriminants (N, Derived_Type); + end if; -- For untagged types, the constraint on the Parent_Type must be -- present and is used to rename the discriminants.