From patchwork Thu Aug 1 15:17:33 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: 95079 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 8085F384B813 for ; Thu, 1 Aug 2024 15:40:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 052AD3858430 for ; Thu, 1 Aug 2024 15:18:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 052AD3858430 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 052AD3858430 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722525535; cv=none; b=d64Fa2OB5vchfCvAkdhWmHbi3+7qTbndL55x0ij1NFqG1EvVqS1JKA7S6jNphophak8ITJQRkUAOtEM5Yz4Anr1S4dqDcm79AotWn6LM94DqihFFJeX7L0S1Ya9/75vOyxdT1fbgheiml2D6rHoLBKF6ito35v3Am+7FnfKV8wk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722525535; c=relaxed/simple; bh=U1FhOFPElcaGZcgJOZgcXETufc0gQ3w7vnCHTx0TxhM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hmlkEGXHLQ+3kLcusWh9OeMJTUzLa3wzTdsssL2fnDkLa72Uc38djVUSWccB0BurJ/ZR40kuxlOpYYJUbbH8hChodivdLD2Z2myLQPeV6dAExURw/u0Q8kftV48b9n4HH0RiUH+e8UX6VZ7XgjGDp15bYQi/uB/zrqy6k1zsDRo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-52f04150796so11642673e87.3 for ; Thu, 01 Aug 2024 08:18:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1722525511; x=1723130311; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RbPh7DVVo1KM5PLxS6ayGvb+LEogvz9Cp2JDezs71kU=; b=d+dM0eey/9hBxs0ZboO4ib6+OSZ+Zjvt/XN8ixBGv+nRvPpP6ZkNmZYdZm7GkEQ97r 4J79fVlaIIsLlmBdw4as9Y7SlYf9RXVqf1skF7SV//qK1TlIvjA5LfdxkZ9Po1eATMXX gLTbYWQK8FetTBSQzbrhiwNhotDVF74+wc59zzI+WEI6DxKRMB6uXYstGPDQj7WxYzyn bw9LtaaJ8+k2EUCuZVouMoU/S1+u6s0evpOEKiTfz4BnDOa3Lk4Hu41aRGtaI3rNROpQ kot6tAJlIl1JIjJ3DNM2M0+Nz+ycP7CX2eIxWUFbZXH5xyGIMHmHK4HePybyJ2aChFmt Z8qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722525511; x=1723130311; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RbPh7DVVo1KM5PLxS6ayGvb+LEogvz9Cp2JDezs71kU=; b=wHCiiinMyGpNmHMIqy8zNtl8xAV2sUdwUCoSbmlnE1XFzS7+dvysZ5gmLD4zCkBtV4 QNNSgPcci4O9UBwtGpEylmKu3K1ath4zdI0cn6NCPQ2Qkqsbs22iHNaK2luwxClswznW ngWF6UCvBBFxpBgY7vv4+52vpojSEHyhUInQfg04uvEygEtFJ0WtsukyT3hfpK/963VF mW1DvgsjjaxHoByCYR1+v3eP9fBUNVtNJBMM0Z/g42C4nSq2JAXCfYI60Uyn1VTTsTGX n7vks+beu1R2CIbB+gr4KaHvnPLmdMa67+faWpoG4VhKsNDNX9wdnX1E75klx6FcRq0/ fXDQ== X-Gm-Message-State: AOJu0YwghNwFA2MtymJceSFfCDsmYImAJJ0hW1xjo1AO9zIfMB2RYtVl hh9NMRTqQTdz3VaciwhMS91d/Zy+Je/1mmDKZ+YGBwZb83ogM7pFUz0ba9CbCUmgaWi1FO71K4X rvQ== X-Google-Smtp-Source: AGHT+IF0OfH/PQSn/AVbkhf60nmlCX+9qICxDj6jOCZT7SaPn1v4poccrH17CI4rRqmRwywhkEXmQg== X-Received: by 2002:a05:6512:3502:b0:52e:7656:a0f4 with SMTP id 2adb3069b0e04-530bb3a35a9mr173587e87.41.1722525511269; Thu, 01 Aug 2024 08:18:31 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:b6aa:4751:9ea1:da1e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36b36857fdesm20065995f8f.75.2024.08.01.08.18.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:18:30 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED 25/30] ada: Deconstruct workarounds for quantified expressions in contracts Date: Thu, 1 Aug 2024 17:17:33 +0200 Message-ID: <20240801151738.400796-25-poulhies@adacore.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240801151738.400796-1-poulhies@adacore.com> References: <20240801151738.400796-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 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 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~patchwork=sourceware.org@gcc.gnu.org From: Piotr Trojanek Apparently we can always safely set the type of a loop parameter from its discrete subtype definition. It looks like the conditional setting was only necessary when preconditions were expanded into dedicated procedures, but we no longer use this expansion. gcc/ada/ * sem_ch5.adb (Analyze_Loop_Parameter_Specification): Unconditionally set the type of loop parameter. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch5.adb | 46 ++------------------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb index 6a479726e86..e4506036cc2 100644 --- a/gcc/ada/sem_ch5.adb +++ b/gcc/ada/sem_ch5.adb @@ -2823,9 +2823,6 @@ package body Sem_Ch5 is -- forms. In this case it is not sufficient to check the static -- predicate function only, look for a dynamic predicate aspect as well. - function Is_Expanded_Quantified_Expr (N : Node_Id) return Boolean; - -- Return Whether N comes from the expansion of a quantified expression. - procedure Process_Bounds (R : Node_Id); -- If the iteration is given by a range, create temporaries and -- assignment statements block to capture the bounds and perform @@ -2911,16 +2908,6 @@ package body Sem_Ch5 is end if; end Check_Predicate_Use; - --------------------------------- - -- Is_Expanded_Quantified_Expr -- - --------------------------------- - - function Is_Expanded_Quantified_Expr (N : Node_Id) return Boolean is - begin - return Nkind (N) = N_Expression_With_Actions - and then Nkind (Original_Node (N)) = N_Quantified_Expression; - end Is_Expanded_Quantified_Expr; - -------------------- -- Process_Bounds -- -------------------- @@ -3094,16 +3081,6 @@ package body Sem_Ch5 is DS_Copy : Node_Id; - Is_Loop_Of_Expanded_Quantified_Expr : constant Boolean := - Present (Loop_Nod) - and then (Is_Expanded_Quantified_Expr (Parent (Loop_Nod)) - -- We also have to consider the case where the loop was wrapped with - -- Wrap_Loop_Statement. - or else (Present (Parent (Loop_Nod)) - and then Present (Parent (Parent (Loop_Nod))) - and then Is_Expanded_Quantified_Expr - (Parent (Parent (Parent (Loop_Nod)))))); - -- Start of processing for Analyze_Loop_Parameter_Specification begin @@ -3276,28 +3253,9 @@ package body Sem_Ch5 is end if; Mutate_Ekind (Id, E_Loop_Parameter); - Set_Is_Not_Self_Hidden (Id); + Set_Etype (Id, Etype (DS)); - -- A quantified expression which appears in a pre- or post-condition may - -- be analyzed multiple times. The analysis of the range creates several - -- itypes which reside in different scopes depending on whether the pre- - -- or post-condition has been expanded. Update the type of the loop - -- variable to reflect the proper itype at each stage of analysis. - - -- Loop_Nod might not be present when we are preanalyzing a class-wide - -- pre/postcondition since preanalysis occurs in a place unrelated to - -- the actual code and the quantified expression may be the outermost - -- expression of the class-wide condition. - - if No (Etype (Id)) - or else Etype (Id) = Any_Type - or else - (Present (Etype (Id)) - and then Is_Itype (Etype (Id)) - and then Is_Loop_Of_Expanded_Quantified_Expr) - then - Set_Etype (Id, Etype (DS)); - end if; + Set_Is_Not_Self_Hidden (Id); -- Treat a range as an implicit reference to the type, to inhibit -- spurious warnings.