From patchwork Wed May 18 08:43:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 54126 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 03C4C3858407 for ; Wed, 18 May 2022 08:47:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 03C4C3858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652863669; bh=zvOaopNXA8yrfGqSMRIqNik/UKUmyi/1eMWNQ0sS0G0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=WEeS11fAqD5c2GhYOPt69nOYU+NJvLqUOboBkC1MMgnInHLvlIdyFehxRG0UAsW1P f4u+0Bib5SSjw6pz7bAKu3HowQmSAGafEZfmiFyJ/AydS6vBUkuBQUfW+pDIZs2hjl 0Tk1pZESedQLnSwIP9/b5MTQf3u7QLZ9rYcZYmTY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 6F2EB3857822 for ; Wed, 18 May 2022 08:43:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6F2EB3857822 Received: by mail-wm1-x333.google.com with SMTP id i20-20020a05600c355400b0039456976dcaso1970854wmq.1 for ; Wed, 18 May 2022 01:43:06 -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=zvOaopNXA8yrfGqSMRIqNik/UKUmyi/1eMWNQ0sS0G0=; b=GGCK+NgP8Lq5EHRblZT975QhkHUKCrYJN7V7RhZg7KLEpXKefVaNnmrHA+ggN7L+dq xz/iI0jGtAurSr7WZGlrRMUSbU3BBQTls43oAueJf/i2rAUUQasos2fmSnUw9EYerehY Y+tb0ah+fmUqIvqkEDv8uxeh3UdunTkXmxG9AAKTJecG86CpRrxOtctUzW5SCSR9dS1y +M1JFSy9+h/bO/xnuywNZG3f729VKppCg2bcezljkCDiavlLwwYHBj3xsl/DHuJG2boR +TFKBcrJKUkWdKQsyVBpGL/oD5pFmpenLwNXCadgDr+OZzNz9T/S17DY4RYzl1EW3Usn 5uww== X-Gm-Message-State: AOAM530aujZg5tMk309g5B9juXvfFwsXfp4hbgGQbAuIfVRPrWdsXUw4 IbeRO0Y+5gUZIW0yt2YIYucb3BiurRkiMw== X-Google-Smtp-Source: ABdhPJwoG62M1b3QwJTIR9k3+rmcMMteWLa5CcBENtfO+bCnJ6oFrjzaBH6o8DqpZPT/2m07pn2TmA== X-Received: by 2002:a05:600c:1c84:b0:394:5de0:2475 with SMTP id k4-20020a05600c1c8400b003945de02475mr25100223wms.27.1652863385116; Wed, 18 May 2022 01:43:05 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id 22-20020a05600c231600b003944821105esm1153260wmo.2.2022.05.18.01.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 01:43:04 -0700 (PDT) Date: Wed, 18 May 2022 08:43:04 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Freezing too strict in instances Message-ID: <20220518084304.GA3298083@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.3 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-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Should_Freeze_Type is relaxed to only take the relevant case into account (entities denoted by generic actual parameters as per 13.14(5/3), as well as profile of any subprograms named as per 13.14(10.2/4)), instead of being overly conservative wrt instances and as a result, wrongly rejecting some legal code. In practice this means we only need to worry about profile of subprograms named as part of instances. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * freeze.adb (Should_Freeze_Type): Fix handling of freezing in instances. diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -184,9 +184,11 @@ package body Freeze is -- the designated type. Otherwise freezing the access type does not freeze -- the designated type. - function Should_Freeze_Type (Typ : Entity_Id; E : Entity_Id) return Boolean; - -- If Typ is in the current scope or in an instantiation, then return True. - -- ???Expression functions (represented by E) shouldn't freeze types in + function Should_Freeze_Type + (Typ : Entity_Id; E : Entity_Id; N : Node_Id) return Boolean; + -- If Typ is in the current scope, then return True. + -- N is a node whose source location corresponds to the freeze point. + -- ??? Expression functions (represented by E) shouldn't freeze types in -- general, but our current expansion and freezing model requires an early -- freezing when the dispatch table is needed or when building an aggregate -- with a subtype of Typ, so return True also in this case. @@ -198,7 +200,7 @@ package body Freeze is ------------------------ function Should_Freeze_Type - (Typ : Entity_Id; E : Entity_Id) return Boolean + (Typ : Entity_Id; E : Entity_Id; N : Node_Id) return Boolean is function Is_Dispatching_Call_Or_Aggregate (N : Node_Id) return Traverse_Result; @@ -244,7 +246,8 @@ package body Freeze is begin return Within_Scope (Typ, Current_Scope) - or else In_Instance + or else (Nkind (N) = N_Subprogram_Renaming_Declaration + and then Present (Corresponding_Formal_Spec (N))) or else (Present (Decl) and then Nkind (Decl) = N_Expression_Function and then Need_Dispatch_Table (Expression (Decl)) = Abandon); @@ -4606,7 +4609,7 @@ package body Freeze is end if; if not From_Limited_With (F_Type) - and then Should_Freeze_Type (F_Type, E) + and then Should_Freeze_Type (F_Type, E, N) then Freeze_And_Append (F_Type, N, Result); end if; @@ -4786,7 +4789,7 @@ package body Freeze is Set_Etype (E, R_Type); end if; - if Should_Freeze_Type (R_Type, E) then + if Should_Freeze_Type (R_Type, E, N) then Freeze_And_Append (R_Type, N, Result); end if;