From: Ed Schonberg Date: Thu, 19 Sep 2019 08:14:08 +0000 (+0000) Subject: [Ada] Spurious visibility error in generic child unit X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=46fa6b050e81504aab992d58b693aa81dd45eeb9;p=gcc.git [Ada] Spurious visibility error in generic child unit 2019-09-19 Ed Schonberg gcc/ada/ * sem_ch7.adb (Install_Parent_Private_Declarations): If a generic child unit is instantiated within a sibling child unit, the analysis of its private part requires that the private part of the ancestor be available, as is done when the context includes an instance of the ancestor. gcc/testsuite/ * gnat.dg/generic2-child.ads, gnat.dg/generic2-io_any.adb, gnat.dg/generic2-io_any.ads, gnat.dg/generic2.ads: New testcase. From-SVN: r275949 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 8c88e906105..e761f701fe7 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,11 @@ +2019-09-19 Ed Schonberg + + * sem_ch7.adb (Install_Parent_Private_Declarations): If a + generic child unit is instantiated within a sibling child unit, + the analysis of its private part requires that the private part + of the ancestor be available, as is done when the context + includes an instance of the ancestor. + 2019-09-19 Yannick Moy * inline.adb (Can_Be_Inlined_In_GNATprove_Mode): Add special diff --git a/gcc/ada/sem_ch7.adb b/gcc/ada/sem_ch7.adb index f7998c0d75b..db6bffd9674 100644 --- a/gcc/ada/sem_ch7.adb +++ b/gcc/ada/sem_ch7.adb @@ -1508,9 +1508,21 @@ package body Sem_Ch7 is Inst_Par := Renamed_Entity (Inst_Par); end if; - Gen_Par := - Generic_Parent - (Specification (Unit_Declaration_Node (Inst_Par))); + -- The instance may appear in a sibling generic unit, in + -- which case the prefix must include the common (generic) + -- ancestor, which is treated as a current instance. + + if Inside_A_Generic + and then Ekind (Inst_Par) = E_Generic_Package + then + Gen_Par := Inst_Par; + pragma Assert (In_Open_Scopes (Gen_Par)); + + else + Gen_Par := + Generic_Parent + (Specification (Unit_Declaration_Node (Inst_Par))); + end if; -- Install the private declarations and private use clauses -- of a parent instance of the child instance, unless the diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index da23e2cd5af..a3534f1442f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-09-19 Ed Schonberg + + * gnat.dg/generic2-child.ads, gnat.dg/generic2-io_any.adb, + gnat.dg/generic2-io_any.ads, gnat.dg/generic2.ads: New testcase. + 2019-09-19 Yannick Moy * gnat.dg/global2.adb, gnat.dg/global2.ads: New testcase. diff --git a/gcc/testsuite/gnat.dg/generic2-child.ads b/gcc/testsuite/gnat.dg/generic2-child.ads new file mode 100644 index 00000000000..291cb23ecd8 --- /dev/null +++ b/gcc/testsuite/gnat.dg/generic2-child.ads @@ -0,0 +1,5 @@ +generic +package Generic2.Child is +private + type My_Int is new Int; +end Generic2.Child; diff --git a/gcc/testsuite/gnat.dg/generic2-io_any.adb b/gcc/testsuite/gnat.dg/generic2-io_any.adb new file mode 100644 index 00000000000..f077ad622cb --- /dev/null +++ b/gcc/testsuite/gnat.dg/generic2-io_any.adb @@ -0,0 +1,5 @@ +-- { dg-do compile } + +package body Generic2.IO_Any is + procedure Dummy is null; +end Generic2.IO_Any; \ No newline at end of file diff --git a/gcc/testsuite/gnat.dg/generic2-io_any.ads b/gcc/testsuite/gnat.dg/generic2-io_any.ads new file mode 100644 index 00000000000..e56e229b114 --- /dev/null +++ b/gcc/testsuite/gnat.dg/generic2-io_any.ads @@ -0,0 +1,6 @@ +with Generic2.Child; +generic +package Generic2.IO_Any is + package V1 is new Generic2.Child; + procedure Dummy; +end Generic2.IO_Any; diff --git a/gcc/testsuite/gnat.dg/generic2.ads b/gcc/testsuite/gnat.dg/generic2.ads new file mode 100644 index 00000000000..295d6b25c3c --- /dev/null +++ b/gcc/testsuite/gnat.dg/generic2.ads @@ -0,0 +1,5 @@ +generic +package Generic2 is +private + type Int is new Integer; +end Generic2;