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: 70146 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7B5893882101 for ; Fri, 26 May 2023 07:45:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B5893882101 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685087106; 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=ZHhAGr7n+zOo1eM/SaRQmuHCBSS+cXDP3HNqjQE3zOh/CMAkPwz3xy0MrowtsTxPM ZSxQff8zTzs6Y8G42v4YXMsWsAld9o1xAd1QBSCYtbUCRG3qYqye1L2OrSqY/zarx9 Hglx9/Cdzmc89dCEq4oUoSwj45AQFnlRqCzYz+vU= 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-Google-Smtp-Source: ACHHUZ5R9FYh3lziS8/+D30hCCKBesEIoyeeh4LmFlotyIGd65930M7cicD6pYmgHafcULsIiss64A== 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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.