From patchwork Mon Feb 26 12:24:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 206607 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2033980dyb; Mon, 26 Feb 2024 04:26:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV/nsCm9SvLKTUDX9vY4PGKjKPjMIyI2hSN8jQQ+LqobXlqTL+l99/CbS7jeqhraal1VDhVJ51zXR+N6yb72l7d1WBq2Q== X-Google-Smtp-Source: AGHT+IEhZD+QBLMxub0KV45Z735nmr3cbcVFbJp9msENIiYamGloRBhYMfC9woWT3MWD9DF2wcNf X-Received: by 2002:a9d:65d7:0:b0:6e4:8c93:7406 with SMTP id z23-20020a9d65d7000000b006e48c937406mr6977295oth.14.1708950371405; Mon, 26 Feb 2024 04:26:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708950371; cv=pass; d=google.com; s=arc-20160816; b=MPazh+l2hTfyfiTZJqGumki+K92xMX+YPV8DuYcYLgz48LK8ZgnJGQ0pCJKtEDaLb0 Ehrn1IkgEGrIXbfdYGKELsce04N35sR6pP5R0hAunmTqK/8QVhm0jjDc17BxUlClWJCW nTDzQSkTUXzxoKL3vFNNoit2607z+iJLeL+Dl8FaiTwiz7kNRfx5B00l2V+7DQ+YkAO/ 5XMRkjcSjfExbIBsTGEFXeaXto0jJOhIi1FooM5p1Js2t4SC9lbMq+dA28DQZgFz4WzD ZUctCXXHNf6VbUwL89IxFrUkI8Vk+y6AAWxhhlH5Y2onSfTS+Cz6OKhJD0JN9rpOQYpx ekng== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=dcDHEVt9Stl6VaeLd/HLojJGnHtFEC4zPrtZb22dHjM=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=jYAplzZwSDIEJ1ggy9vpZIExHnKyAZzuXPZFVrURoDd/wuny5gxbkL1TWclB/9inn/ VDm0EwwEM3lKbcm7GsuUYtRMDR11pryAlVf9tv3zF0QT1ZYJV1c978wJKNRoEn64tOGZ PdT/NHajExnrMle3J2Hy2Hob5hWCURXn6i2Yym0cSPG2zZ6KO8arGnPYmSSrUfCeVh5c J1TPi6MgP9z5tPontgZjuSg24PYQaL4PauYQVpO6M9NGjmo6pneRRd1d2iZEmJ8WGL/Z 1/shaBzWUm/eU/kKt/OkPKr/IlaB+r2EPujNPJ+Mfbh0JiGM/38/FVodcze7sN/ezrue XMIw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=aHJV2Ieg; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id z5-20020a05620a100500b00787b4b48b39si4938999qkj.439.2024.02.26.04.26.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 04:26:11 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=aHJV2Ieg; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1BE803858D28 for ; Mon, 26 Feb 2024 12:26:11 +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 2C04A3858C39 for ; Mon, 26 Feb 2024 12:24:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C04A3858C39 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 2C04A3858C39 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=1708950299; cv=none; b=Zyl9HYTP8XGhJaQ9e/l2+p4qyKAJo/6/z9O18Pt8nrQF4icz2LBX9DcF5iMfxZ02S1jNKbW+FfDwrGQnagUzGGuN6HGmVmYaTF59LX6PaSF7tJT/RJ4RkkfvzTLSYfqpJ8JJLGmBsIlIOC6YqeoeooIV+96VCK4qC83ZfAZLVjk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708950299; c=relaxed/simple; bh=u33DDUKUl0Ai4ncGzIsSyjofJuQwDc4goPF0jLSEzcs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QHS+VfYudQ1smqTJd2Qgkq7ANsQH44ADcZT6prYhoHREWCGgOwhEWTrO8sTJA72TfFPBUTlO1NqjLkzMpbrTu69EJ7Fw6Wj6TZB8Xbs5b/Cquy88kqSkmpOsUKrdcrKcX0OnvZHnZFlfLSmgjZQmnhAh+gvTveEE0u5VrGOgWZE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-412a14299a4so11070725e9.1 for ; Mon, 26 Feb 2024 04:24:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1708950296; x=1709555096; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=dcDHEVt9Stl6VaeLd/HLojJGnHtFEC4zPrtZb22dHjM=; b=aHJV2IegOM5UeTlJpBlggwKCvj34PphnjSmqOrqnYPTKXblR+Q21VWo3tRmCJIaDBN jpnHCYgEcZPTk06ERgq4YhUxjZR+YdgO2zpV6h38OTQfjyfVYSW770r7m53LUI162ZeE j5SUHiIk55UOtMsk6gOV3E9XNR+mK2J0FtATbUjSVIgZ2JcVH/x0fcfBOsKShW4EscCP LlFd7UWL4HqMVXTht3Gwnjye7630UUrxT1kXLBnAwzEpr+sPqEQQDoYmOSKNIfdj0I05 p6kZOazGEcrMzPGJEBasM8GTv7m9QkisqPzHcqx+a6BG5MQc/Ke6PkgqxEkoaaW/U257 Ozng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708950296; x=1709555096; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dcDHEVt9Stl6VaeLd/HLojJGnHtFEC4zPrtZb22dHjM=; b=jvJPuGXCGjj2Ljpgf+UtFrJoysVJ8c5FdmCiV/5NKF8J+RWoTGJ3hOWkCEKMrobkJi 3Sh/qNvO5tQ4Rs9hhEKelgJnINPPmDOwPt7U6m5JBhXKY9NBywZUoZieKtXLcMs4MuRx +T+F/PWj73hz7dZezcMiCu2fd1gOOWwL5BmBVrRdjW0h06b3w27AE/L9aOOYZ0EpOeCx YEUUOFmlKVPROxAXv0hfgCEuM69+5kmJi0YxRSiOjuZ9YZQX7O5yVk50Oyk0PG1cRuyW LXqMm4jLvvZVYArZI6/svznPFym2AIjF2X5oT08NBXubzIbkLxos6SrCU3hlNcKRnlTT CaOg== X-Gm-Message-State: AOJu0YzQ+axDe/J1h3scdiU5W53/NUlheCM6XUqyPWPuMO23rKEnlz9s VH+g6GtssyUHtwiaad6fBO/j7dVT9CScsaGtvKenq8gQKO1k3C8Y/JgKr2XWedUua3LJHwPvAJ8 = X-Received: by 2002:a05:600c:4f52:b0:412:8872:e8f4 with SMTP id m18-20020a05600c4f5200b004128872e8f4mr5326459wmq.1.1708950295234; Mon, 26 Feb 2024 04:24:55 -0800 (PST) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id fa13-20020a05600c518d00b00412a7cf0308sm1609375wmb.3.2024.02.26.04.24.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 04:24:54 -0800 (PST) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix PR ada/113893 Date: Mon, 26 Feb 2024 13:24:54 +0100 Message-ID: <3290278.44csPzL39Z@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791964344940727533 X-GMAIL-MSGID: 1791964344940727533 The finalization of objects dynamically allocated through an anonymous access type is deferred to the enclosing library unit in the current implementation and a warning is given on each of them. However this cannot be done if the designated type is local, because this would generate dangling references to the local finalization routine, so the finalization needs to be dropped in this case and the warning adjusted. Tested on x86-64/Linux, applied on all active branches. 2024-02-26 Eric Botcazou PR ada/113893 * exp_ch7.adb (Build_Anonymous_Master): Do not build the master for a local designated type. * exp_util.adb (Build_Allocate_Deallocate_Proc): Force Needs_Fin to false if no finalization master is attached to an access type and assert that it is anonymous in this case. * sem_res.adb (Resolve_Allocator): Mention that the object might not be finalized at all in the warning given when the type is an anonymous access-to-controlled type. 2024-02-26 Eric Botcazou * gnat.dg/access10.adb: New test. diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb index 2ac73101351..e594a534244 100644 --- a/gcc/ada/exp_ch7.adb +++ b/gcc/ada/exp_ch7.adb @@ -749,6 +749,7 @@ package body Exp_Ch7 is Desig_Typ : Entity_Id; FM_Id : Entity_Id; Priv_View : Entity_Id; + Scop : Entity_Id; Unit_Decl : Node_Id; Unit_Id : Entity_Id; @@ -787,6 +788,18 @@ package body Exp_Ch7 is Desig_Typ := Priv_View; end if; + -- For a designated type not declared at library level, we cannot create + -- a finalization collection attached to an outer unit since this would + -- generate dangling references to the dynamic scope through access-to- + -- procedure values designating the local Finalize_Address primitive. + + Scop := Enclosing_Dynamic_Scope (Desig_Typ); + if Scop /= Standard_Standard + and then Scope_Depth (Scop) > Scope_Depth (Unit_Id) + then + return; + end if; + -- Determine whether the current semantic unit already has an anonymous -- master which services the designated type. diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb index 31cd47de7d2..04d114694ab 100644 --- a/gcc/ada/exp_util.adb +++ b/gcc/ada/exp_util.adb @@ -936,6 +936,16 @@ package body Exp_Util is Needs_Finalization (Desig_Typ) and then not No_Heap_Finalization (Ptr_Typ); + -- The allocation/deallocation of a controlled object must be associated + -- with an attachment to/detachment from a finalization master, but the + -- implementation cannot guarantee this property for every anonymous + -- access tyoe, see Build_Anonymous_Collection. + + if Needs_Fin and then No (Finalization_Master (Ptr_Typ)) then + pragma Assert (Ekind (Ptr_Typ) = E_Anonymous_Access_Type); + Needs_Fin := False; + end if; + if Needs_Fin then -- Do nothing if the access type may never allocate / deallocate @@ -945,11 +955,6 @@ package body Exp_Util is return; end if; - -- The allocation / deallocation of a controlled object must be - -- chained on / detached from a finalization master. - - pragma Assert (Present (Finalization_Master (Ptr_Typ))); - -- The only other kind of allocation / deallocation supported by this -- routine is on / from a subpool. diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index 8e9714c1c86..075c0d85ccd 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -5679,19 +5679,19 @@ package body Sem_Res is Set_Is_Dynamic_Coextension (N, False); Set_Is_Static_Coextension (N, False); - -- Anonymous access-to-controlled objects are not finalized on - -- time because this involves run-time ownership and currently - -- this property is not available. In rare cases the object may - -- not be finalized at all. Warn on potential issues involving - -- anonymous access-to-controlled objects. + -- Objects allocated through anonymous access types are not + -- finalized on time because this involves run-time ownership + -- and currently this property is not available. In rare cases + -- the object might not be finalized at all. Warn on potential + -- issues involving anonymous access-to-controlled types. if Ekind (Typ) = E_Anonymous_Access_Type and then Is_Controlled_Active (Desig_T) then Error_Msg_N - ("??object designated by anonymous access object might " + ("??object designated by anonymous access value might " & "not be finalized until its enclosing library unit " - & "goes out of scope", N); + & "goes out of scope, or not be finalized at all", N); Error_Msg_N ("\use named access type instead", N); end if; end if;