From patchwork Fri Aug 2 07:11:26 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: 1968199 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=I2SJ6VNn; 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 4WZxw84Tgmz1yYq for ; Fri, 2 Aug 2024 17:16:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C8577385EC59 for ; Fri, 2 Aug 2024 07:16:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id C98F6385E45A for ; Fri, 2 Aug 2024 07:12:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C98F6385E45A 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 C98F6385E45A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::233 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722582754; cv=none; b=O9836OkYRnrCBnoYMb33zkIsPHuO3WonIJWfnQYeep21vK+OuJhDXgDXzkrDU6m8N+3+JePkRgY1aseVt5+z7BkODXR/HVVy7PjMlAbgjozVl1YR+qRMtmmH0NP0I3feig44bnxlWaGe+sO3RF7GaXBsFu4F6dJHOYBO9CjIg2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722582754; c=relaxed/simple; bh=ul77WTuGULC///hd6s4wYYYCMSrUkDxg7wFZNoZGNb0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=CEBbB7heynGF4kWEs/9nKY7xq/wR2oncMYxkge+MNQBrQKjrBVM77kLRnJ/W30bZDuNdJA4Y5CtZR0uX4L+BgnrE1xCvuR00xaFGtQn0hzLKO1tTgny1dYHZIsrTkF46pSEhGWzI4JAsi0Jhk/I6QS/n6PaxVsu0wooup3p/qFY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2ef2c56d9dcso96924281fa.2 for ; Fri, 02 Aug 2024 00:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1722582750; x=1723187550; 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=Juv2vhUyVEr1Wc5bM5qybMDFqJ0K0NJxttDIpmGPKeA=; b=I2SJ6VNnzqONiuasjQyGAKjgjPii63daNjxiOYX3Vqjg15AB3dDJ/1kXXDq70YYnWI WJEj2vf9b77gyFyu3IwPJdBjWPNakB3S34kzlAsYg0blTScbkrOIhz30xJpQ9zXEO7hK kqQM4Nnv1riA6qbrlQyOYre+lqsgXTFLqLzMunCAe4fGkcdashd4J6XuKJnfCIDz7mX2 0gr4JTfFgUIzdO8ECGgYv7qu+08wo3dCCk/dfDJ3DDySbO840aTvSObeOwsoXoiGb60B 5BXmDdAmtMGc5GXmSfv6bnm3xZEdgd3n6LZfWHgmXyflbMDG4JqLLB60gIps3dvggQ65 9Xtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722582750; x=1723187550; 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=Juv2vhUyVEr1Wc5bM5qybMDFqJ0K0NJxttDIpmGPKeA=; b=vaWfJrWTjCsLvvwku0JF6B3qgFDzNQHbjIvlU76rXuTtfiwGV2GFq3LCfuIm5YGNnI YFp3sYNtneFzVDSC/bY6vJ3Kx8L1Qgh/1BhkIAsLYKDmi5Gg10nhFi0TtcuKwlgnsv81 E4zNR7t+DiAguD3masWMQsI8CPUy6aeISjFcsJZ+pL3hXRqa9GRo4Th/tVjFHuHy5zi4 0ImxSuczgGvEZ2Zyd7cCcWwnkGPJy+DvmIWnDAq3WmhKrqqkkI5+Rf79/OBKCjykZQpC g8MqZPSX8MH/cyBKsMJkMGe7oaQikj0g71czR0Lm5DLLqisemjyHLUKofUg68o0pkE4F BiHw== X-Gm-Message-State: AOJu0YxSGJIdWxY3QVp3N20a68BjOY002qrUWGjW3/O8SrwnU7+FROvR LoU+yT7jauwoVJC/b/usrCJxrJHRZGd9BBZ88YAuMo/7u7Tlj3zTnIUvIp5szj2JDoQ10OwLIxu pFw== X-Google-Smtp-Source: AGHT+IGaiCa1VNcNoVcOmVsQxdF8Mh2JIgly8xaSB1TrRz34gIA7NC52kv2mqjWFD7BOH6pO3ul/8w== X-Received: by 2002:a05:6512:3d18:b0:52c:e03d:dfd7 with SMTP id 2adb3069b0e04-530bb39b0bcmr1586358e87.39.1722582750161; Fri, 02 Aug 2024 00:12:30 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 00:12:29 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED 09/26] ada: Finish up support for relaxed finalization Date: Fri, 2 Aug 2024 09:11:26 +0200 Message-ID: <20240802071210.413366-9-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.8 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: Eric Botcazou This adds a variant of the System.Finalization_Primitives unit that supports only controlled types with relaxed finalization, and adds the description of its implementation to Exp_Ch7. gcc/ada/ * exp_ch7.adb (Relaxed Finalization): New paragraph in head comment. * sem_ch13.adb (Validate_Finalizable_Aspect): Give an error message if strict finalization is required but not supported by the runtime. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch7.adb | 58 ++++++++++++++++++++++++++++++++++++++++++++ gcc/ada/sem_ch13.adb | 18 +++++++++++--- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb index 044b14ad305..b545a58448d 100644 --- a/gcc/ada/exp_ch7.adb +++ b/gcc/ada/exp_ch7.adb @@ -337,6 +337,64 @@ package body Exp_Ch7 is -- directly by the compiler during the expansion of allocators and calls to -- instances of the Unchecked_Deallocation procedure. + -------------------------- + -- Relaxed Finalization -- + -------------------------- + + -- This paragraph describes the differences between the implementation of + -- finalization as specified by the Ada RM (called "strict" and documented + -- in the previous paragraph) and that of finalization as specified by the + -- GNAT RM (called "relaxed") for a second category of controlled objects. + + -- For objects (statically) declared in a scope, the default implementation + -- documented in the previous paragraph is used for the scope as a whole as + -- soon as one controlled object with strict finalization is present in it, + -- including one transient controlled object. Otherwise, that is to say, if + -- all the controlled objects in the scope have relaxed finalization, then + -- no Finalization_Master is built for this scope, and all the objects are + -- finalized explicitly in the reverse order of their creation: + + -- declare + -- X : Ctrl := Init; + -- Y : Ctrl := Init; + + -- begin + -- null; + -- end; + + -- is expanded into: + + -- declare + -- XMN : aliased System.Finalization_Primitives.Master_Node; + -- X : Ctrl := Init; + -- System.Finalization_Primitives.Attach_To_Node + -- (X'address, + -- CtrlFD'unrestricted_access, + -- XMN'unrestricted_access); + -- YMN : aliased System.Finalization_Primitives.Master_Node; + -- Y : Ctrl := Init; + -- System.Finalization_Primitives.Attach_To_Node + -- (Y'address, + -- CtrlFD'unrestricted_access, + -- YMN'unrestricted_access); + + -- procedure _Finalizer is + -- begin + -- Abort_Defer; + -- System.Finalization_Primitives.Finalize_Object (YMN); + -- System.Finalization_Primitives.Finalize_Object (XMN); + -- Abort_Undefer; + -- end _Finalizer; + + -- begin + -- null; + -- end; + -- at end + -- _Finalizer; + + -- Dynamically allocated objects with relaxed finalization need not be + -- finalized and, therefore, are not attached to any finalization chain. + type Final_Primitives is (Initialize_Case, Adjust_Case, Finalize_Case, Address_Case); -- This enumeration type is defined in order to ease sharing code for diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 55b0a7a5ccf..3fb0209f612 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -17907,9 +17907,10 @@ package body Sem_Ch13 is -- If Relaxed_Finalization is set, the Finalize and Adjust procedures -- are considered as having the No_Raise aspect specified. - if Has_Relaxed_Finalization (Typ) - and then Serious_Errors_Detected = 0 - then + if Serious_Errors_Detected > 0 then + null; + + elsif Has_Relaxed_Finalization (Typ) then Assoc := First (Component_Associations (Aggr)); while Present (Assoc) loop Nam := First (Choices (Assoc)); @@ -17922,8 +17923,17 @@ package body Sem_Ch13 is Next (Assoc); end loop; - end if; + -- If Relaxed_Finalization is not set, then check that the support for + -- strict finalization is available in the runtime library. + + elsif not In_Predefined_Unit (Cunit (Get_Source_Unit (Typ))) + and then not RTE_Available (RE_Finalization_Master) + then + Error_Msg_N + ("only Relaxed Finalization is supported in this configuration", + ASN); + end if; end Validate_Finalizable_Aspect; ------------------------------