From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id 05B55385AC0A for ; Tue, 12 Jul 2022 12:25:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 05B55385AC0A Received: by mail-ed1-x52c.google.com with SMTP id y8so9890494eda.3 for ; Tue, 12 Jul 2022 05:25:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=+LQCQ3CwvD5OJe+6kuj1IHZe2glNvEX4GdYmBxKPdkU=; b=Ek5HXaGx5tikqHYWtm1L+YUXEz7Q23TQSXHL5Ff4/nKCDkeAsp310fF9iaHnsDrwb2 PXJZwNBbZlvSSuTIXqDtO4+WWRaaChT+bNQv6RsQD/ZnB6kACTMH2fjnjlk2hE+l4sgZ W7s1oiuA36eoC/CnlaQpDyCHj2gahhwV1LNkOjYNalcntRNJPHQcDe9+Fb6dYdZ0/JnX PZsIgXkA0X6lr74EUvtIpN61Vtf6muTVkd7g6AE3qNLELToxCLHhgyPkNdv99kRoZsOY gOMFPP+ZGFdZsm9mpqdbGDvZUUB7PSKzU2FEf1fjIrCYOX0FRU6+INvBQoL6UKBpZAOy jcUA== X-Gm-Message-State: AJIora9ahyWHnpSgEFqCwr6FfT/kuMPjJQ0YRqvriJWUV1H5075k4Kse hSv/GVgqZ5Xw6YJ8YU66vhH7YWJvk/dCmQ== X-Google-Smtp-Source: AGRyM1tPEM6ZZCdKJBhdWq0BxDtIXiuLsbD/zrlNZXTRsm9G1kBRUvLY3heB+KOJQoaipL8hVA6wdQ== X-Received: by 2002:a05:6402:11cb:b0:43a:b592:efbb with SMTP id j11-20020a05640211cb00b0043ab592efbbmr26615558edw.157.1657628726864; Tue, 12 Jul 2022 05:25:26 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id i17-20020a05640200d100b00435c10b5daesm5948303edu.34.2022.07.12.05.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 05:25:26 -0700 (PDT) Date: Tue, 12 Jul 2022 12:25:25 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [Ada] Do not create large objects for indefinite protected types Message-ID: <20220712122525.GA3404821@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="2fHTh5uZTiUOsy+g" Content-Disposition: inline X-Spam-Status: No, score=-13.2 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, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Jul 2022 12:25:29 -0000 --2fHTh5uZTiUOsy+g Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This plugs a small loophole in the Needs_Secondary_Stack predicate for some protected types and record types containing protected components. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_util.adb (Caller_Known_Size_Record): Make entry assertion more robust and add guard for null argument. For protected types, invoke Caller_Known_Size_Record on Corresponding_Record_Type. (Needs_Secondary_Stack): Likewise. --2fHTh5uZTiUOsy+g Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -23305,7 +23305,7 @@ package body Sem_Util is ------------------------------ function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is - pragma Assert (Typ = Underlying_Type (Typ)); + pragma Assert (if Present (Typ) then Typ = Underlying_Type (Typ)); function Depends_On_Discriminant (Typ : Entity_Id) return Boolean; -- Called for untagged record and protected types. Return True if Typ @@ -23342,6 +23342,14 @@ package body Sem_Util is end Depends_On_Discriminant; begin + -- This is a protected type without Corresponding_Record_Type set, + -- typically because expansion is disabled. The safe thing to do is + -- to return True, so Needs_Secondary_Stack returns False. + + if No (Typ) then + return True; + end if; + -- First see if we have a variant part and return False if it depends -- on discriminants. @@ -23367,14 +23375,18 @@ package body Sem_Util is Underlying_Type (Etype (Comp)); begin - if Is_Record_Type (Comp_Type) - or else - Is_Protected_Type (Comp_Type) - then + if Is_Record_Type (Comp_Type) then if not Caller_Known_Size_Record (Comp_Type) then return False; end if; + elsif Is_Protected_Type (Comp_Type) then + if not Caller_Known_Size_Record + (Corresponding_Record_Type (Comp_Type)) + then + return False; + end if; + elsif Is_Array_Type (Comp_Type) then if Size_Depends_On_Discriminant (Comp_Type) then return False; @@ -23478,7 +23490,7 @@ package body Sem_Util is begin -- This is a private type which is not completed yet. This can only -- happen in a default expression (of a formal parameter or of a - -- record component). Do not expand transient scope in this case. + -- record component). The safe thing to do is to return False. if No (Typ) then return False; @@ -23533,12 +23545,17 @@ package body Sem_Util is elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then return Large_Max_Size_Mutable (Typ); - -- Indefinite (discriminated) record or protected type + -- Indefinite (discriminated) record type - elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then + elsif Is_Record_Type (Typ) then return not Caller_Known_Size_Record (Typ); - -- Unconstrained array + -- Indefinite (discriminated) protected type + + elsif Is_Protected_Type (Typ) then + return not Caller_Known_Size_Record (Corresponding_Record_Type (Typ)); + + -- Unconstrained array type else pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ)); --2fHTh5uZTiUOsy+g--