From patchwork Fri Aug 2 07:11:43 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: 1968215 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=M1vepmzl; 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 4WZy5H4BDYz1yZl for ; Fri, 2 Aug 2024 17:24:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F55D3858428 for ; Fri, 2 Aug 2024 07:24:33 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by sourceware.org (Postfix) with ESMTPS id E786C385332C for ; Fri, 2 Aug 2024 07:12:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E786C385332C 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 E786C385332C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::232 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722582770; cv=none; b=Hq62XrE/OJZ9E3rnQC1TGiypnzFnQ3pGSbiH8i+MyrtySXSQ6Nm2LCj+n2pDXe/Iy4SgS8EZ8zojFZZe/8TaPJxlgnINwqsZhjMh2MVCYLoqSvz7DWLzll38pzF0+d+bfmsjFNMuOYtNi6QDSK29sYsPtu0vckHuIyC1dSGQGD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722582770; c=relaxed/simple; bh=OvvHDjZuJG+Qh/x5IfCbeFwuoBeX8S88r9c+HQ1YhAg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fiK0VHv8rxBLzWfeNiUJ16fU0hhpDbm5URd0wYZ6+/Jvwi1wg+x/3t6ZaTvmu9iJYXXQDTheDoJKqj5oaVj8rW7MUxQTLpQxu2978WVMwUvItl4IWO/UBL4JI5DZcaHZpCVYMCS3AKNiOVAMC6OzYkVVB3gMFEOdSHrFnrA63Mw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2f025b94e07so100120581fa.0 for ; Fri, 02 Aug 2024 00:12:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1722582764; x=1723187564; 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=5Qd7iwud649++zbBWxgyaOQQd7JxYNbGuuTqe4ewhXc=; b=M1vepmzl/3sBPXaQ92xn4H5buVzYw8yCeNAHCZUg57sI8NF1GspwGLFl1WjpvKN7Mk 1ZBRuEDkYpdwwvV0Pf9Qj90Uu3MLz1FYlfE+syO7ocsXEnDRz0/zs0AEJuMwZ2P+rTkx laZE5wPd3d9+ahMdy0ty6e9OggwdIl5IdjD+6JSiSSJXs3zqhy8I6iy7asi3c06PFZjC tsxVHNdzMj09l11f5ZfuBst8jgBFfJH9wAGxjAQlPGx8c6ft9muOvDSvQ4+SYSPRbdJP sHJqTZQdYD5ToKg4muySMuydRBx9aMb4KlPaVJz4HWyzR3vfjVtAJiWQKfAk96oGN27O o27A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722582764; x=1723187564; 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=5Qd7iwud649++zbBWxgyaOQQd7JxYNbGuuTqe4ewhXc=; b=MR5br6gCdCEqIZ9HdLIV3K0DSOg5qNH2y8hyD3uWeF2N6WnwO604EVRRE2EzPgdO2U YCBxSiWsDgra7wGjzDPQX8lyQmw1OReOhg7Y7GDAkWCbBG9AjoILp4WTi8JmfGETfUpv zQtyHVpJYIrBJp/KBQWvryMonK0DHim3k8D6zAb9AL7u0TLAyB2b0RN6eABrngHA3L41 lg23jG0vW1POvK6qn2vWbSfMWfY0+CnUELteqICSE6qr1+l3dGuj/A+5K809n5sJm4EW vwt6GgxD57mQbUmJhOMLRU8qr39ytmlj0IY4/Cx4/WnDZIcyN6kLibq9xJ8fIaKCYL6E DOAw== X-Gm-Message-State: AOJu0YxB/xk0TC31nvjlFVrlzcKXXMxuyETZ40VgrfBYt9ED5cbBKa4q DzBN7j8UeAiM2RreQQDIn2ERVECNfs0e0146eX+MvGXb3wRCsNV7JzqqZ8Fo4jRdjCzC11n3nCo ipA== X-Google-Smtp-Source: AGHT+IHfOv+M6Ekr8NOAi3ZT7ZwlJpLGq0N1zhUYN0n/ctl5WiO7MNYMpp76ptI8yrxq/w4Seld0ag== X-Received: by 2002:a05:6512:32c7:b0:52c:d76f:7f61 with SMTP id 2adb3069b0e04-530bb3a47f4mr1420669e87.56.1722582764211; Fri, 02 Aug 2024 00:12:44 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:b6aa:4751:9ea1:da1e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36bbd059932sm1195770f8f.69.2024.08.02.00.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 00:12:43 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Yannick Moy Subject: [COMMITTED 26/26] ada: Fix handling of SPARK_Mode on standalone child subprogram Date: Fri, 2 Aug 2024 09:11:43 +0200 Message-ID: <20240802071210.413366-26-poulhies@adacore.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240802071210.413366-1-poulhies@adacore.com> References: <20240802071210.413366-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: Yannick Moy SPARK_Mode aspect was not properly propagated to the body of a standalone child subprogram from the generated spec for that subprogram, leading GNATprove to not analyze this body. Now fixed. gcc/ada/ * aspects.adb (Find_Aspect): Take into account the case of a node of kind N_Defining_Program_Unit_Name. * sem_ch10.adb (Analyze_Compilation_Unit): Copy the SPARK aspect from the spec to the body. Delay semantic analysis after that point to ensure that SPARK_Mode is properly analyzed. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/aspects.adb | 8 +++++++- gcc/ada/sem_ch10.adb | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gcc/ada/aspects.adb b/gcc/ada/aspects.adb index b7262c56f3f..4c8ab7b4a33 100644 --- a/gcc/ada/aspects.adb +++ b/gcc/ada/aspects.adb @@ -190,13 +190,19 @@ package body Aspects is -- Note that not all aspects are added to the chain of representation -- items. In such cases, search the list of aspect specifications. First -- find the declaration node where the aspects reside. This is usually - -- the parent or the parent of the parent. + -- the parent or the parent of the parent, after getting through the + -- additional indirection of the N_Defining_Program_Unit_Name if needed. if No (Parent (Owner)) then return Empty; end if; Decl := Parent (Owner); + + if Nkind (Decl) = N_Defining_Program_Unit_Name then + Decl := Parent (Decl); + end if; + if not Permits_Aspect_Specifications (Decl) then Decl := Parent (Decl); diff --git a/gcc/ada/sem_ch10.adb b/gcc/ada/sem_ch10.adb index 73e5388affd..e56fe30adae 100644 --- a/gcc/ada/sem_ch10.adb +++ b/gcc/ada/sem_ch10.adb @@ -1046,17 +1046,27 @@ package body Sem_Ch10 is Set_Library_Unit (N, Lib_Unit); Set_Parent_Spec (Unit (Lib_Unit), Cunit (Unum)); Make_Child_Decl_Unit (N); - Semantics (Lib_Unit); -- Now that a separate declaration exists, the body -- of the child unit does not act as spec any longer. Set_Acts_As_Spec (N, False); Move_Aspects (From => Unit_Node, To => Unit (Lib_Unit)); + + -- Ensure that the generated corresponding spec and + -- original body share the same SPARK_Mode pragma or + -- aspect. As a result, both have the same SPARK_Mode + -- attributes, and the global SPARK_Mode value is + -- correctly set for local subprograms. + + Copy_SPARK_Mode_Aspect (Unit (Lib_Unit), To => Unit_Node); + Set_Is_Child_Unit (Defining_Entity (Unit_Node)); Set_Debug_Info_Needed (Defining_Entity (Unit (Lib_Unit))); Set_Comes_From_Source_Default (SCS); + Semantics (Lib_Unit); + -- Restore Context_Items to the body Set_Context_Items (N, Context_Items (Lib_Unit));