From patchwork Thu Jan 6 17:13:10 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: 1576211 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=eezkm0FQ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JVD3C4pn9z9sXM for ; Fri, 7 Jan 2022 04:33:27 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 84DA13858035 for ; Thu, 6 Jan 2022 17:33:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 84DA13858035 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641490405; bh=uJ46BnpkTp4bm/+OKydRKhs2EVxrjPsqFvEufUbXZmk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=eezkm0FQLvUtxw+0Gy5PI/k7pljyiRV9Qsho+PAFSr6x699656VKyh/L0FT91/9rc SFC+DK0hozZgUq53DdjVj1AudQz+QI41BjoVRDnkcSnXP4pAuAeSHYykqJHqcx8M0Q h5WcG1ko/mHXap7X1YBS87x6ywyKUP0m4qjC5ey8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 3B4233858020 for ; Thu, 6 Jan 2022 17:13:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3B4233858020 Received: by mail-wr1-x42f.google.com with SMTP id k18so6069974wrg.11 for ; Thu, 06 Jan 2022 09:13:13 -0800 (PST) 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=uJ46BnpkTp4bm/+OKydRKhs2EVxrjPsqFvEufUbXZmk=; b=i+yfDXJfca6DhRInAWn7FEQnuJrM5lwHH2tYfTfDFBSj3PUVKN0EGnC7UEbrj4LVdB jm9rAYzE1ya7+w3yI0+eaGMVI4P0UbVJCPS+D3waRAAdWl6BZH81XjtPeFjdrxeHycJ8 ponSZl6qaYVZ6eC4pqom/kfoi5breBrKmT5DJ0RVp6YOEgaBfBK+VmtO7UT51e/yoXYS RCwP3g7Gwsa53+7a1C+KWfJF5VCaKvelhQFJUUvjs6pK2p1q8xNfDW4I7uh1rY3jP+qU A7rJXoDEduWHye2HnFlZiZx0uE3C7rdVAXlmhi0K2L7KbVKIngn8lvGNrKGt8c0FPVIy 3Yiw== X-Gm-Message-State: AOAM531CAR/BrjsIkAnzYYjh1vfxY5lXc/vjuYNsY13s+QQQ72J3NR2y 11bK/OFOoiPSbG1Ceck6t+OzUqsErqNnzw== X-Google-Smtp-Source: ABdhPJy1fBABmghSceyED+3HmmTj/rWzbZPfDUliHw9TYG1kN0ctkXqbkDXJ/F2Tpe8TDopiVgImDw== X-Received: by 2002:a05:6000:2ce:: with SMTP id o14mr51830285wry.70.1641489192040; Thu, 06 Jan 2022 09:13:12 -0800 (PST) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id c8sm2514202wmq.34.2022.01.06.09.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 09:13:11 -0800 (PST) Date: Thu, 6 Jan 2022 17:13:10 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix regression in freezing code for instantiations Message-ID: <20220106171310.GA2921734@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.1 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Cc: Eric Botcazou Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" When going to the outer level for the placement of a freeze node in the case where the current package has no body, the previous change would overlook instantiations whose body has not materialized yet. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch12.adb (Insert_Freeze_Node_For_Instance): When going to the outer level, do not jump over following instantiations in the list. diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -9703,6 +9703,7 @@ package body Sem_Ch12 is Decl : Node_Id; Decls : List_Id; Inst : Entity_Id; + Origin : Entity_Id; Par_Inst : Node_Id; Par_N : Node_Id; @@ -9793,9 +9794,10 @@ package body Sem_Ch12 is end; end if; - Decl := N; - Decls := List_Containing (N); - Par_N := Parent (Decls); + Decl := N; + Decls := List_Containing (N); + Par_N := Parent (Decls); + Origin := Empty; -- Determine the proper freeze point of an instantiation @@ -9824,10 +9826,13 @@ package body Sem_Ch12 is not In_Same_Source_Unit (Generic_Parent (Par_Inst), Inst) then while Present (Decl) loop - if (Nkind (Decl) in N_Unit_Body + if ((Nkind (Decl) in N_Unit_Body or else - Nkind (Decl) in N_Body_Stub) - and then Comes_From_Source (Decl) + Nkind (Decl) in N_Body_Stub) + and then Comes_From_Source (Decl)) + or else (Present (Origin) + and then Nkind (Decl) in N_Generic_Instantiation + and then Instance_Spec (Decl) /= Origin) then Set_Sloc (F_Node, Sloc (Decl)); Insert_Before (Decl, F_Node); @@ -9851,16 +9856,19 @@ package body Sem_Ch12 is return; -- When the instantiation occurs in a package spec and there is - -- no source body which follows, not even of the package itself - -- then insert into the declaration list of the outer level. + -- no source body which follows, not even of the package itself, + -- then insert into the declaration list of the outer level, but + -- do not jump over following instantiations in this list because + -- they may have a body that has not materialized yet, see above. elsif Nkind (Par_N) = N_Package_Specification and then No (Corresponding_Body (Parent (Par_N))) and then Is_List_Member (Parent (Par_N)) then - Decl := Parent (Par_N); - Decls := List_Containing (Decl); - Par_N := Parent (Decls); + Decl := Parent (Par_N); + Decls := List_Containing (Decl); + Par_N := Parent (Decls); + Origin := Decl; -- In a package declaration, or if no source body which follows -- and at library level, then insert at end of list.