diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2018-12-03 15:49:17 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2018-12-03 15:49:17 +0000 |
commit | d71753da57c28ded0e9d392c119ffbcdc0396360 (patch) | |
tree | e33f1dfab933ed791859f35d468a5c4bb37f6af3 /gcc | |
parent | 9f8483ca8f858ea19e3e0fcf567820e3195fe2de (diff) | |
download | gcc-d71753da57c28ded0e9d392c119ffbcdc0396360.zip gcc-d71753da57c28ded0e9d392c119ffbcdc0396360.tar.gz gcc-d71753da57c28ded0e9d392c119ffbcdc0396360.tar.bz2 |
[Ada] Fix internal error on package instantiation on private type
This fixes an assertion failure in gigi triggered by the instantiation
of a generic package, in a visible part of another package, done on a
private type whose full view is a type derived from a scalar or an
access type.
The problem is that the front-end creates and inserts two different
freeze nodes in the expanded tree for the partial and the full views of
the private subtype created by the instantiation, which is not correct:
partial and full views of a given (sub)type must point to the same
freeze node, if any.
The patch also adds an assertion checking this property in the front-end
so as to catch the inconsistency higher in the chain.
2018-12-03 Eric Botcazou <ebotcazou@adacore.com>
gcc/ada/
* freeze.adb (Freeze_Entity): Do not freeze the partial view of
a private subtype if its base type is also private with delayed
freeze before the full type declaration of the base type has
been seen.
* sem_ch7.adb (Preserve_Full_Attributes): Add assertion on
freeze node.
gcc/testsuite/
* gnat.dg/generic_inst2.adb, gnat.dg/generic_inst2.ads,
gnat.dg/generic_inst2_c.ads: New testcase.
From-SVN: r266754
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/ada/freeze.adb | 25 | ||||
-rw-r--r-- | gcc/ada/sem_ch7.adb | 9 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/generic_inst2.adb | 5 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/generic_inst2.ads | 10 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/generic_inst2_c.ads | 5 |
7 files changed, 66 insertions, 2 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 481f9da..2a3ff0f 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,5 +1,14 @@ 2018-12-03 Eric Botcazou <ebotcazou@adacore.com> + * freeze.adb (Freeze_Entity): Do not freeze the partial view of + a private subtype if its base type is also private with delayed + freeze before the full type declaration of the base type has + been seen. + * sem_ch7.adb (Preserve_Full_Attributes): Add assertion on + freeze node. + +2018-12-03 Eric Botcazou <ebotcazou@adacore.com> + * exp_ch3.adb (Build_Record_Init_Proc): Inherit an initialization procedure if it is present, even if it is null. diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index afb3479..412789f 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -6239,13 +6239,34 @@ package body Freeze is goto Leave; - -- Case of no full view present. If entity is derived or subtype, + -- Case of no full view present. If entity is subtype or derived, -- it is safe to freeze, correctness depends on the frozen status -- of parent. Otherwise it is either premature usage, or a Taft -- amendment type, so diagnosis is at the point of use and the -- type might be frozen later. - elsif E /= Base_Type (E) or else Is_Derived_Type (E) then + elsif E /= Base_Type (E) then + declare + Btyp : constant Entity_Id := Base_Type (E); + + begin + -- However, if the base type is itself private and has no + -- (underlying) full view either, wait until the full type + -- declaration is seen and all the full views are created. + + if Is_Private_Type (Btyp) + and then No (Full_View (Btyp)) + and then No (Underlying_Full_View (Btyp)) + and then Has_Delayed_Freeze (Btyp) + and then No (Freeze_Node (Btyp)) + then + Set_Is_Frozen (E, False); + Result := No_List; + goto Leave; + end if; + end; + + elsif Is_Derived_Type (E) then null; else diff --git a/gcc/ada/sem_ch7.adb b/gcc/ada/sem_ch7.adb index 28119df..d85f847 100644 --- a/gcc/ada/sem_ch7.adb +++ b/gcc/ada/sem_ch7.adb @@ -2733,6 +2733,15 @@ package body Sem_Ch7 is Propagate_Concurrent_Flags (Priv, Base_Type (Full)); end if; + -- As explained in Freeze_Entity, private types are required to point + -- to the same freeze node as their corresponding full view, if any. + -- But we ought not to overwrite a node already inserted in the tree. + + pragma Assert (Serious_Errors_Detected /= 0 + or else No (Freeze_Node (Priv)) + or else No (Parent (Freeze_Node (Priv))) + or else Freeze_Node (Priv) = Freeze_Node (Full)); + Set_Freeze_Node (Priv, Freeze_Node (Full)); -- Propagate Default_Initial_Condition-related attributes from the diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b69ad66..2e63d0a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2018-12-03 Eric Botcazou <ebotcazou@adacore.com> + * gnat.dg/generic_inst2.adb, gnat.dg/generic_inst2.ads, + gnat.dg/generic_inst2_c.ads: New testcase. + +2018-12-03 Eric Botcazou <ebotcazou@adacore.com> + * gnat.dg/overload2.adb, gnat.dg/overload2_p.adb, gnat.dg/overload2_p.ads, gnat.dg/overload2_q.adb, gnat.dg/overload2_q.ads: New testcase. diff --git a/gcc/testsuite/gnat.dg/generic_inst2.adb b/gcc/testsuite/gnat.dg/generic_inst2.adb new file mode 100644 index 0000000..2ccebb0 --- /dev/null +++ b/gcc/testsuite/gnat.dg/generic_inst2.adb @@ -0,0 +1,5 @@ +-- { dg-do compile } + +package body Generic_Inst2 is + procedure Foo (X : not null access T) is null; +end; diff --git a/gcc/testsuite/gnat.dg/generic_inst2.ads b/gcc/testsuite/gnat.dg/generic_inst2.ads new file mode 100644 index 0000000..3124a1d --- /dev/null +++ b/gcc/testsuite/gnat.dg/generic_inst2.ads @@ -0,0 +1,10 @@ +with Generic_Inst2_C; + +package Generic_Inst2 is + type T is private; + procedure Foo (X : not null access T); + package CI is new Generic_Inst2_C (T, Foo => Foo); +private + type S is access Integer; + type T is new S; +end; diff --git a/gcc/testsuite/gnat.dg/generic_inst2_c.ads b/gcc/testsuite/gnat.dg/generic_inst2_c.ads new file mode 100644 index 0000000..df1000b --- /dev/null +++ b/gcc/testsuite/gnat.dg/generic_inst2_c.ads @@ -0,0 +1,5 @@ +generic + type T; + with procedure Foo (X : not null access T) is null; + with procedure Bar (X : not null access T) is null; +package Generic_Inst2_C is end; |