From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id AAC92385840E for ; Thu, 5 Jan 2023 14:39:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AAC92385840E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wr1-x42e.google.com with SMTP id r2so1510795wrv.7 for ; Thu, 05 Jan 2023 06:39:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=bUdYGxJk3wlgs9vQxmvpkQDhhJoVz3MzSzlO76bti9w=; b=KIIxVpA50V0+vMuyTqK+CUPP7wztSu46yY7/yTE23syZRAhYpv2478Xcg8GsJxwhhA p4XRhuWrYg/6hmFYwyPcYB6bzWCxbDq01OyQw/eLmeq0RW//qsNoveVZHOKIUGbkAfX+ vSl+hkjAynXSsMwEtNYS3RJcvvbthsEFRqi0aa9o+5IjyDEYJr9kVfUpo/KZMGsboF5/ aD6RxSJ8zlk8ysFFoMkVf1UFzNxFosM6UHMCKgaUVaQi4OzKm4ZbeQW4FwdJyJ/7n9dJ pl6sPfCnyKTtShIgi8tLTyzMvnJu19S7fkLmQ0T52iqihPrNxvj53pAOFS6N+524Ugqb ek9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bUdYGxJk3wlgs9vQxmvpkQDhhJoVz3MzSzlO76bti9w=; b=CeO7JaxW1ldafCqwHRKqLsnHy6nfRTGrHuw8qlgRA3lMYEDtqvXjhM8ncuIOPuTXOo tY2ze6/jo5bQQ528JjE5VUsIT8S8v0/FDBdsHN4SLuNbdYgd3iobuYHlNbLGHSdWqroT 7ENtFuYN/4kiLZ76gsQp7NU5zcHis1znM0krs5vnzulmjqvIGnLflGBtTwlukdJFJsHz V200ZgZTHWdACfnfGDG5DCDe98qEnKjYnt5fZwjuWf6jbGuWNy999wHV1tH8F9gNoefb wDP+U0FuPGFslprRp31Cy5sXICMef5XcG9BBv0ZX6Ep/cmwT+84pXCua3jxD94DBNZ7w hDvQ== X-Gm-Message-State: AFqh2kqhk/r/wrgrAtkl7lCqk7dLwwIdRumhbqGlwX2HwC+rfHEBX71q FO22iyh5MMIYRD/Ks3oP9Jlw+SsiPI5n2EtMYVA= X-Google-Smtp-Source: AMrXdXvSMAnlqkUUed1WKa1QIs6Fi0CmpX1O4zmAqsd1zSJqhzp/q7RGc0/ost0Z1sGd6AidWEvc6w== X-Received: by 2002:a05:6000:1a47:b0:242:12cf:fba8 with SMTP id t7-20020a0560001a4700b0024212cffba8mr38509497wry.55.1672929560532; Thu, 05 Jan 2023 06:39:20 -0800 (PST) Received: from poulhies-Precision-5550.lan (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm36691544wrq.10.2023.01.05.06.39.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 06:39:20 -0800 (PST) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Subject: [COMMITTED] ada: Fix generic instantiation of sibling package Date: Thu, 5 Jan 2023 15:39:18 +0100 Message-Id: <20230105143918.155693-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.6 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: The compiler would crash because it is failing at setting up the scope stack correctly for a generic instantiation of a sibling package within a child package instance. In this case, the parent instance isn't explicitly referenced and it must be found differently. gcc/ada/ * sem_ch12.adb (Instantiate_Package_Body): Correctly find the parent instance to place on the scope stack. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch12.adb | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb index 1ea95845a16..0f2dd39b53c 100644 --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -12150,8 +12150,26 @@ package body Sem_Ch12 is end; -- If it is a child unit, make the parent instance (which is an - -- instance of the parent of the generic) visible. The parent - -- instance is the prefix of the name of the generic unit. + -- instance of the parent of the generic) visible. + + -- 1) The child unit's parent is an explicit parent instance (the + -- prefix of the name of the generic unit): + + -- package Child_Package is new Parent_Instance.Child_Unit; + + -- 2) The child unit's parent is an implicit parent instance (e.g. + -- when instantiating a sibling package): + + -- generic + -- package Parent.Second_Child is + -- ... + + -- generic + -- package Parent.First_Child is + -- package Sibling_Package is new Second_Child; + + -- 3) The child unit's parent is not an instance, so the scope is + -- simply the one of the unit. if Ekind (Scope (Gen_Unit)) = E_Generic_Package and then Nkind (Gen_Id) = N_Expanded_Name @@ -12161,6 +12179,17 @@ package body Sem_Ch12 is Install_Parent (Par_Ent, In_Body => True); Par_Installed := True; + elsif Ekind (Scope (Gen_Unit)) = E_Generic_Package + and then Ekind (Scope (Act_Decl_Id)) = E_Package + and then Is_Generic_Instance (Scope (Act_Decl_Id)) + then + Par_Ent := Entity + (Prefix (Name (Get_Unit_Instantiation_Node + (Scope (Act_Decl_Id))))); + Par_Vis := Is_Immediately_Visible (Par_Ent); + Install_Parent (Par_Ent, In_Body => True); + Par_Installed := True; + elsif Is_Child_Unit (Gen_Unit) then Par_Ent := Scope (Gen_Unit); Par_Vis := Is_Immediately_Visible (Par_Ent); -- 2.34.1