From patchwork Fri Jun 21 08:57:58 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: 1950627 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=gIY3OOxC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W5B9l3kmgz20X8 for ; Fri, 21 Jun 2024 18:59:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B602A38983AB for ; Fri, 21 Jun 2024 08:59:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 97C463894C27 for ; Fri, 21 Jun 2024 08:58:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 97C463894C27 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 97C463894C27 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::331 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718960314; cv=none; b=ju1LU8Azp26onwylXKZCrJrhzC+8uxE17Ea2jBBZb3cN7wRG5KKO+plRs92q3lHMj2PrL1FwFzkqE1dlVrOuVur4FEJCQTrOWWtqAeh1dFW1Ld0smtIoi16Ugc1TDvVYFDej+zggU+swRiuBI/isd/O2oTGBgH52XIzlpXO2vOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718960314; c=relaxed/simple; bh=EdnFvkGZ67G0GyHpCk00DZ5EHWoRm+qj14NGf3aFy20=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dGxkH8HwNDWSL0HQ0ysKfrUH+fo6SDg+g2mz8ohfwc9nQ6ax84zeOYT96BkzlJybTZ2vzWUP/dG2iBZZMjx56pyRiU85bHKo5RFIbT4MoyGP/Liva85YyCKMRwaFscZeVhXNtzBhiifiqUhXvU5F3OHHBpP3L2ykWu2+Uj8hjxo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4217dbeb4caso16003195e9.1 for ; Fri, 21 Jun 2024 01:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1718960311; x=1719565111; 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=uvAdpQMQ+Wt1zpYA7XMuTlpNM7uyJ5apLPu+mLlEsvU=; b=gIY3OOxCVEMCS2IXOEEnw5VS6O0UKz+f1FLAhSuJSoq2cNYWyItDSIHjgTT4RGvuTU k0CWCCVvSqhlvbo+A8z0Y+ZkWMjBBdqQ1o5jqCNvnLFJ6RBLXZApnTa7KqerE8TuiHJT yZonEJSgev2rjD2zJP2/IdYqFs2Eg5jugSKXfon4bdISHb7LJ1e6al7M4DU5AQK3Ejac cliLrnPBpCJf4bJvYFGPEsQOQLLFf1NlAysOKBab769+s+OhtKeKGRreumo93Z3UfkA7 vFeUSeV29fYj011TwiDtfE3DCEBp7touV/o0Rnarq/4XomRoOGQH0BJ17i5P81XC1JX7 fAbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718960311; x=1719565111; 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=uvAdpQMQ+Wt1zpYA7XMuTlpNM7uyJ5apLPu+mLlEsvU=; b=iPYEGzl2ede+HIJ6NlCLORf7fKiM8Z0602D/VFuBWaygGolVbQuywZsFtZM6a3u6Js 7l3uK1hrGPJSN0BuDK0pGZu238a14fUmmoawYAOPjCVQR0CpwTCViReSSRGeMSUVmGa0 zMZxztFBFRrHqA7p2dv0p81q0vNe4YsRMDhct7jOo8pfsG3wQEjBv8E+20+yqV1n82yr 5VBnFKSepe3WiQ8cf8CZiX4VkrcwKi7HH8Y6kHXZTQkzv0B3S2hu5z60LPlLH1Ff0gee 2Za30euzDN1moTkicTW08Rl4yCGQSJD344olWT0k3P8XAXJa9XrCf70DCvK/D1YDDaWW +Z7g== X-Gm-Message-State: AOJu0YwVec/Csu7RTfURCfR7MY6wIIKDGKVi0umHE4c2otEeWxSLDog5 g6Ewp5jEBc/qLkFXi6VDR/BVmZ0Rp1jkJjimzZ0ZeRziXOteFm9dYx/YgyWT6sUcsKpSdH0VGxM = X-Google-Smtp-Source: AGHT+IEPSVUBuXYT3D58T3PtFtY3rU95J6ipqccZ0BUwGPaB9VPF6wJXQuMXl7Sj0OW8THHQf5tNsQ== X-Received: by 2002:a05:600c:3587:b0:422:6e65:a4cb with SMTP id 5b1f17b1804b1-4247507865fmr61340085e9.3.1718960311304; Fri, 21 Jun 2024 01:58:31 -0700 (PDT) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:a589:2704:bfe1:5d92]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d0c5485sm55322375e9.21.2024.06.21.01.58.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 01:58:30 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED 02/22] ada: Fix for Default_Component_Value with declare expressions Date: Fri, 21 Jun 2024 10:57:58 +0200 Message-ID: <20240621085819.2485987-2-poulhies@adacore.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240621085819.2485987-1-poulhies@adacore.com> References: <20240621085819.2485987-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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 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+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Piotr Trojanek When the expression of aspect Default_Component_Value includes a declare expression with current type instance, we attempted to recursively froze that type, which itself caused an infinite recursion, because we didn't properly manage the scope of declare expression. This patch fixes both the detection of the current type instance and analysis of the expression that caused recursive freezing. gcc/ada/ * sem_attr.adb (In_Aspect_Specification): Use the standard condition that works correctly with declare expressions. * sem_ch13.adb (Analyze_Aspects_At_Freeze_Point): Replace ordinary analysis with preanalysis of spec expressions. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_attr.adb | 4 +++- gcc/ada/sem_ch13.adb | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index 72f5ab49175..d56c25a79cc 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -1843,7 +1843,9 @@ package body Sem_Attr is if Nkind (P) = N_Aspect_Specification then return P_Type = Entity (P); - elsif Nkind (P) in N_Declaration then + -- Prevent the search from going too far + + elsif Is_Body_Or_Package_Declaration (P) then return False; end if; diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 4012932a6f2..a86f774018a 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -1037,11 +1037,19 @@ package body Sem_Ch13 is Parent_Type : Entity_Id; + Save_In_Spec_Expression : constant Boolean := In_Spec_Expression; + begin -- Ensure Expr is analyzed so that e.g. all types are properly - -- resolved for Find_Type_Reference. + -- resolved for Find_Type_Reference. We preanalyze this expression + -- as a spec expression (to avoid recursive freezing), while skipping + -- resolution (to not fold type self-references, e.g. T'Last). - Analyze (Expr); + In_Spec_Expression := True; + + Preanalyze (Expr); + + In_Spec_Expression := Save_In_Spec_Expression; -- A self-referential aspect is illegal if it forces freezing the -- entity before the corresponding aspect has been analyzed.