From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id E957E3858410 for ; Mon, 20 May 2024 07:49:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E957E3858410 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 E957E3858410 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716191377; cv=none; b=XacZQzH2k00WiAfWvKA8WSMCKGNYINef4ps1ypPgqwV4EwXTP3MA6KM/VUEJsxO5bcYZdCyP/dr7Hn8NoX5lUnqpitsN+p3blKPem8uMeCPrP8+tLlHSVBb5vVmdAoyPXKoP0ghruweDRmsnpJa6d94zHG4SFRfbxP98fkLhC4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716191377; c=relaxed/simple; bh=tHsQ5afRfzvOfCROuFVhW+3CK952lehL6gqu+6fA4C0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XDueMRWt3tygoaw9Bal/uyYqqdq4idez2Mdcy3RdEKmrIpZu9YXYgLHQ62weIH0ZS3qx+APGnd4KhegX8c4mIg1IkRGC29RYiXj91QI2VKKyx6Kn61X2rBlXSrs2hc9Um3KXr59Jk2g/EzOOIEFJOqyftpV+adx3TGPzCFfBszM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4202ca70318so15897715e9.1 for ; Mon, 20 May 2024 00:49:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1716191372; x=1716796172; 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=0jbsWIUjNdWbDUk5g9ZJDNXy5jaJfunmOe3+xb/1JJA=; b=i7nN/ANvmXcYfN7PI3X12XOc9zLPl6UMeD3nAonQMRs42y4/iy5TuPp0Zm0zz+XBlQ PJfcbhcUMg/6Veo/2RcC+mZyC4C89oVmGOYnFehJ90aqu4HPhBSs5sES6vN6OfVfkhTM /atamUN2OwYKwJnu/7XsIdDG173ySycNuv1AVDOyYNhMmvO/maxeTfBkERsR/VIRwyAW cO/reKD+1q35QRh0qTixnhyKHKAgYWejKmtHdLSUnAgo2u4uK+qncVvzwYm55G4H49+8 QvDVHb2V87M+NLLcM9cOsuaq1Wi/KYFTqQthwSGBGMkS4MXBCrIN9JYrxKS4kOT8nnpK Zosg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716191372; x=1716796172; 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=0jbsWIUjNdWbDUk5g9ZJDNXy5jaJfunmOe3+xb/1JJA=; b=AQjqh7R0ldNSv/BzAAVFf7VgeD+XX5c6gPofJGZf7vZXpkYv3iNZV44F4JuozvYRqx XCy6PMMJuQYrnZAsqBJLHtLEVyvT9h8TlusaNeC2l07//YcITtx1TTsJtCnruE5G9/A/ hUcjqbj9raSdnfK3hNI0wdGfy4b9knXhh2UrYwI+cE93IGD7fV8DbdoP0hZuN2OZJZD0 mzaN+AjfwfJwKcQI0UibTMdWIag7j99n3ui9Z4Maovhs+EDocFnqTxDGBtkEF5J63HJC Tt8gPIMsnwHWaiqFGogvwwMWhKhMLlXzUAsx5KlYquL7dYLTKWwZAcD8jOa6pOVKlo2A oxLw== X-Gm-Message-State: AOJu0YwwoFv8Ol8xSsWKjDsVmc0Ss3DTmWiH9p1TH3RwExuUwE45ZI02 N7wnmgOXR3fwx9PvnzMo/RpwMOBnCBHT6/coSEULZLA43WRUG1NaVFRZB81awvMlVj69uEr9fVg = X-Google-Smtp-Source: AGHT+IFs6HcvNg8P35VBHSwBoBiSqlFBU18QHEpXvXK+Gc44D7gpXyOSNkSc8mYS14VMTAFUHfF87w== X-Received: by 2002:a05:600c:4595:b0:41b:b07a:c54c with SMTP id 5b1f17b1804b1-41feaa30751mr233187105e9.9.1716191372685; Mon, 20 May 2024 00:49:32 -0700 (PDT) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:de37:8b1c:1f33:2610]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41f88111033sm446892175e9.34.2024.05.20.00.49.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 00:49:32 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED 27/30] ada: Get rid of secondary stack for indefinite record types with size clause Date: Mon, 20 May 2024 09:48:53 +0200 Message-ID: <20240520074858.222435-27-poulhies@adacore.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240520074858.222435-1-poulhies@adacore.com> References: <20240520074858.222435-1-poulhies@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.9 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 List-Id: From: Eric Botcazou This change eliminates the use of the secondary stack for indefinite record types for which a valid (object) size clause is specified. In accordance with the RM, the compiler accepts (object) size clauses on such types only if all the components, including those of the variants of the variant part if any, have a size known at compile time, and only if the clauses specify a value that is at least as large as the largest possible size of objects of the types when all the variants are considered. However, it would still have used the secondary stack, despite valid (object) size clauses, before the change, as soon as a variant part was present in the types. gcc/ada/ * freeze.ads (Check_Compile_Time_Size): Remove obsolete description of usage for the Size_Known_At_Compile_Time flag. * freeze.adb (Check_Compile_Time_Size.Size_Known): In the case where a variant part is present, do not return False if Esize is known. * sem_util.adb (Needs_Secondary_Stack.Caller_Known_Size_Record): Add missing "Start of processing" comment. Return true if either a size clause or an object size clause has been given for the first subtype of the type. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/freeze.adb | 1 + gcc/ada/freeze.ads | 11 +++++------ gcc/ada/sem_util.adb | 12 ++++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index 26e9d01d8b2..ea6106e6455 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -1077,6 +1077,7 @@ package body Freeze is and then No (Discriminant_Default_Value (First_Discriminant (T))) and then not Known_RM_Size (T) + and then not Known_Esize (T) then return False; end if; diff --git a/gcc/ada/freeze.ads b/gcc/ada/freeze.ads index fc0b7678fdc..066d8f054f6 100644 --- a/gcc/ada/freeze.ads +++ b/gcc/ada/freeze.ads @@ -156,17 +156,16 @@ package Freeze is -- RM_Size field is set to the required size, allowing for possible front -- end packing of an array using this type as a component type. -- - -- Note: the flag Size_Known_At_Compile_Time is used to determine if the - -- secondary stack must be used to return a value of the type, and also - -- to determine whether a component clause is allowed for a component - -- of the given type. - -- - -- Note: this is public because of one dubious use in Sem_Res??? + -- Note: the flag Size_Known_At_Compile_Time is used to determine whether a + -- size clause is allowed for the type, and also whether a component clause + -- is allowed for a component of the type. -- -- Note: Check_Compile_Time_Size does not test the case of the size being -- known because a size clause is specifically given. That is because we -- do not allow a size clause if the size would not otherwise be known at -- compile time in any case. + -- + -- ??? This is public because of dubious uses in Sem_Ch3 and Sem_Res procedure Check_Inherited_Conditions (R : Entity_Id; diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 09358278210..15994b4d1e9 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -22409,6 +22409,8 @@ package body Sem_Util is return False; end Depends_On_Discriminant; + -- Start of processing for Caller_Known_Size_Record + begin -- This is a protected type without Corresponding_Record_Type set, -- typically because expansion is disabled. The safe thing to do is @@ -22418,6 +22420,16 @@ package body Sem_Util is return True; end if; + -- If either size is specified for the type, then it's known in the + -- caller in particular. Note that, even if the clause is confirming, + -- this does not change the outcome since the size was already known. + + if Has_Size_Clause (First_Subtype (Typ)) + or else Has_Object_Size_Clause (First_Subtype (Typ)) + then + return True; + end if; + -- First see if we have a variant part and return False if it depends -- on discriminants. -- 2.43.2