From patchwork Tue Jul 2 13:21:21 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: 1955283 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=MZ4RrQsq; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4WD3X23fcYz1xpc for ; Tue, 2 Jul 2024 23:23:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B8F0C3882174 for ; Tue, 2 Jul 2024 13:23:44 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id A061D384602A for ; Tue, 2 Jul 2024 13:21:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A061D384602A 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 A061D384602A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719926508; cv=none; b=X6mh6Q+VmvpTW9U4/joL4KzD9Qn0dz6ArJSw+0Ub/uHpUPCrG8stBdBVLV5eB0uCtGEoheVaGUhJPOe1oL+vIIMB2GFnc7TfzJB6HNB/DWfkLT6lcq3LTnw7H+dSqfo0wFDJs4L2ZpHPrpzulJqgP6m1SIYSPZFf3n3uvxhF/mI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719926508; c=relaxed/simple; bh=RyXGgLGcQhScXclJTlykonobKO1dKa+SjmcbYddGH0U=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Zq2QcURkbQgSL/33RQhYyDOgyBXpQAFTM8d7FGfzbv5h9yiqbDQu+XZD5dgq4Ss2f0qEtMjYGCjYUlmP27Sgb0U9zTjfssrZZkgbZMSBZuAEr6Ro1E+TDs9Ce1az15rMoGpUK9ad7dUR5jIkVYltRL+WzyPDp2TdnbiuP2f6eCM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-42573d3f7e4so27344015e9.0 for ; Tue, 02 Jul 2024 06:21:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1719926504; x=1720531304; 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=9p4BMNqMSOnTWdjhNaC/F7LqH8imIZWBWCY3i1nExqM=; b=MZ4RrQsq6GoUjqm4vr9IHDviiOBXyy5JMbEFb8785Xq5EFRcJh3OByYBp4m+3n4/Ep saUiFGt7FYdLx1/5sHgAuW15yr+k0AOUC7z2aHsV8j7hAvGNKapMt34kOmgRW7uiqc7C U2HyeLHMMv6eb23tOYjtrzQa8AZpj7W0fRm2tIEqMLUjkAT9qGwRfaKYM+78wCcJV7Lf gamurl9l/BcDXtuCC9RGmpR39QPYh4i/ayeL9S/X/j/bc05Tz/78Rdt3uYLSKpc8Vhup p9lOVPxlzkVuqn9PR8OIiO8Q8padUWyfEX10xtMKG3fVM9wfIzkqVb5UV/RaVHNyOyY+ b26w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719926504; x=1720531304; 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=9p4BMNqMSOnTWdjhNaC/F7LqH8imIZWBWCY3i1nExqM=; b=SRZRs5qJeza0DwPaWz7Nsf51SWQ6m3BUngUtl3t13eWNMShycRHdj1pO/6gVDdgIC+ laqJsoKlP2sspsrZDZd3B9AAV17xtV8cZqBX+HEm/v91Rh2aFPnYMF47Hpfu36iKH+g9 8XMcsjVQKc+jeSFJb0IRvm/fIcNJLe7WqCmDywN6+mxsLW2EYwxzeGJe3xrEMhZaL33u y8/PeRVDuW1ta3dX+xJngQDnzawdcqnOKTnDwyXdoY126PQlDt9eS8E7flyspNxpWv21 NE6rg5+lSJAuplhz1SmxgX9R8vYCQb5wGQKenS4vPzXtGjHgwhzmCZIvMSAkAAmXLT4H 6gdA== X-Gm-Message-State: AOJu0YwT/2WlyXWXt7PwS3wPLdDITq/TLyqStn+VpeQfduv81DbtWZ5T UmlPa2+hxXs0x7X2DBispIUP3dKtwLU9mwj7B5Y1h7gKPYxdxCiXvMNTw7RpyqUpMQpltJWbvOk = X-Google-Smtp-Source: AGHT+IHQCKEGRBz/OWEGBIorzJIX0r9pBDXD3n3os8bDJV8v+iMGbWec8GzCQj168OgXjjihnvw/Lg== X-Received: by 2002:a7b:c3d9:0:b0:425:66fa:c7cc with SMTP id 5b1f17b1804b1-4257a0793acmr60937605e9.37.1719926504462; Tue, 02 Jul 2024 06:21:44 -0700 (PDT) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:53cf:a5ff:fb60:5a70]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b09abbfsm197319895e9.35.2024.07.02.06.21.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 06:21:43 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Yannick Moy Subject: [COMMITTED 05/13] ada: Fix analysis of Extensions_Visible Date: Tue, 2 Jul 2024 15:21:21 +0200 Message-ID: <20240702132130.523603-5-poulhies@adacore.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240702132130.523603-1-poulhies@adacore.com> References: <20240702132130.523603-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.1 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: Yannick Moy Pragma/aspect Extensions_Visible should be analyzed before any pre/post contracts on a subprogram, as the legality of conversions of formal parameters to classwide type depends on the value of Extensions_Visible. Now fixed. gcc/ada/ * contracts.adb (Analyze_Pragmas_In_Declarations): Analyze pragmas in two iterations over the list of declarations in order to analyze some pragmas before others. * einfo-utils.ads (Get_Pragma): Fix comment. * sem_prag.ads (Pragma_Significant_To_Subprograms): Fix. (Pragma_Significant_To_Subprograms_Analyzed_First): Add new global array to identify these pragmas which should be analyzed first, which concerns only Extensions_Visible for now. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/contracts.adb | 46 ++++++++++++++++++++++++----------------- gcc/ada/einfo-utils.ads | 1 + gcc/ada/sem_prag.ads | 10 +++++++++ 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb index 9fc9e05db68..a93bf622aa1 100644 --- a/gcc/ada/contracts.adb +++ b/gcc/ada/contracts.adb @@ -546,33 +546,41 @@ package body Contracts is begin -- Move through the body's declarations analyzing all pragmas which - -- appear at the top of the declarations. + -- appear at the top of the declarations. Go over the list twice, so + -- that pragmas which should be analyzed first are analyzed in the + -- first pass. - Curr_Decl := First (Declarations (Unit_Declaration_Node (Body_Id))); - while Present (Curr_Decl) loop + for Pragmas_Analyzed_First in reverse False .. True loop - if Nkind (Curr_Decl) = N_Pragma then + Curr_Decl := First (Declarations (Unit_Declaration_Node (Body_Id))); + while Present (Curr_Decl) loop - if Pragma_Significant_To_Subprograms - (Get_Pragma_Id (Curr_Decl)) - then - Analyze (Curr_Decl); - end if; + if Nkind (Curr_Decl) = N_Pragma then - -- Skip the renamings of discriminants and protection fields + if Pragma_Significant_To_Subprograms + (Get_Pragma_Id (Curr_Decl)) + and then Pragmas_Analyzed_First = + Pragma_Significant_To_Subprograms_Analyzed_First + (Get_Pragma_Id (Curr_Decl)) + then + Analyze (Curr_Decl); + end if; - elsif Is_Prologue_Renaming (Curr_Decl) then - null; + -- Skip the renamings of discriminants and protection fields - -- We have reached something which is not a pragma so we can be sure - -- there are no more contracts or pragmas which need to be taken into - -- account. + elsif Is_Prologue_Renaming (Curr_Decl) then + null; - else - exit; - end if; + -- We have reached something which is not a pragma so we can be + -- sure there are no more contracts or pragmas which need to be + -- taken into account. + + else + exit; + end if; - Next (Curr_Decl); + Next (Curr_Decl); + end loop; end loop; end Analyze_Pragmas_In_Declarations; diff --git a/gcc/ada/einfo-utils.ads b/gcc/ada/einfo-utils.ads index 01953c35bc3..8207576fb89 100644 --- a/gcc/ada/einfo-utils.ads +++ b/gcc/ada/einfo-utils.ads @@ -448,6 +448,7 @@ package Einfo.Utils is -- Effective_Reads -- Effective_Writes -- Exceptional_Cases + -- Extensions_Visible -- Global -- Initial_Condition -- Initializes diff --git a/gcc/ada/sem_prag.ads b/gcc/ada/sem_prag.ads index 59220ea890c..557e0454870 100644 --- a/gcc/ada/sem_prag.ads +++ b/gcc/ada/sem_prag.ads @@ -216,6 +216,7 @@ package Sem_Prag is Pragma_Contract_Cases => True, Pragma_Depends => True, Pragma_Exceptional_Cases => True, + Pragma_Extensions_Visible => True, Pragma_Ghost => True, Pragma_Global => True, Pragma_Inline => True, @@ -238,6 +239,15 @@ package Sem_Prag is Pragma_Volatile_Function => True, others => False); + -- The following table lists all pragmas which are relevant to the analysis + -- of subprogram bodies and should be analyzed first, because the analysis + -- of other pragmas relevant to subprogram bodies depend on them. + + Pragma_Significant_To_Subprograms_Analyzed_First : + constant array (Pragma_Id) of Boolean := + (Pragma_Extensions_Visible => True, + others => False); + ----------------- -- Subprograms -- -----------------