diff options
author | Javier Miranda <miranda@adacore.com> | 2021-08-30 08:25:50 -0400 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2021-10-04 08:45:07 +0000 |
commit | 8e1e74a162c751014b43d609207aaf75ed4dd428 (patch) | |
tree | ffae93de10aeff8b3dc00027090aa08ce8107a7c /gcc | |
parent | c36774bcc38ba51fc9091d92a079e5b2d4aab759 (diff) | |
download | gcc-8e1e74a162c751014b43d609207aaf75ed4dd428.zip gcc-8e1e74a162c751014b43d609207aaf75ed4dd428.tar.gz gcc-8e1e74a162c751014b43d609207aaf75ed4dd428.tar.bz2 |
[Ada] Fix latent problem in Sem_Ch8.Build_Class_Wide_Wrapper
gcc/ada/
* sem_ch8.adb (Build_Class_Wide_Wrapper): Fix handling of
class-wide subtypes; required to handle chains of
instantiations. Adding also code to identify these wrappers and
properly resolve instantiations where the wrapper and a tagged
type primitive are visible.
* einfo.ads (Is_Class_Wide_Wrapper): Adding documentation.
* gen_il-fields.ads (Opt_Field_Enum): Adding
Is_Class_Wide_Wrapper.
* gen_il-gen-gen_entities.adb (Root_Entity_Type): Adding
semantic flag Is_Class_Wide_Wrapper.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/einfo.ads | 8 | ||||
-rw-r--r-- | gcc/ada/gen_il-fields.ads | 1 | ||||
-rw-r--r-- | gcc/ada/gen_il-gen-gen_entities.adb | 1 | ||||
-rw-r--r-- | gcc/ada/sem_ch8.adb | 15 |
4 files changed, 23 insertions, 2 deletions
diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads index 2030841..0239a70 100644 --- a/gcc/ada/einfo.ads +++ b/gcc/ada/einfo.ads @@ -2429,6 +2429,11 @@ package Einfo is -- Is_Class_Wide_Type (synthesized) -- Applies to all entities, true for class wide types and subtypes +-- Is_Class_Wide_Wrapper +-- Defined in subprogram entities. Indicates that it has been created as +-- a wrapper in a generic/instance scenario involving a formal type and +-- a generic primitive operation when the actual is a class-wide type. + -- Is_Compilation_Unit -- Defined in all entities. Set if the entity is a package or subprogram -- entity for a compilation unit other than a subunit (since we treat @@ -5562,6 +5567,7 @@ package Einfo is -- Ignore_SPARK_Mode_Pragmas -- Is_Abstract_Subprogram (non-generic case only) -- Is_Called (non-generic case only) + -- Is_Class_Wide_Wrapper -- Is_Constructor -- Is_CUDA_Kernel (non-generic case only) -- Is_DIC_Procedure (non-generic case only) @@ -5734,6 +5740,7 @@ package Einfo is -- Default_Expressions_Processed -- Has_Nested_Subprogram -- Ignore_SPARK_Mode_Pragmas + -- Is_Class_Wide_Wrapper -- Is_Elaboration_Checks_OK_Id -- Is_Elaboration_Warnings_OK_Id -- Is_Intrinsic_Subprogram @@ -5924,6 +5931,7 @@ package Einfo is -- Is_Abstract_Subprogram (non-generic case only) -- Is_Asynchronous -- Is_Called (non-generic case only) + -- Is_Class_Wide_Wrapper -- Is_Constructor -- Is_CUDA_Kernel -- Is_DIC_Procedure (non-generic case only) diff --git a/gcc/ada/gen_il-fields.ads b/gcc/ada/gen_il-fields.ads index f8bfe6e..f3f3ca4 100644 --- a/gcc/ada/gen_il-fields.ads +++ b/gcc/ada/gen_il-fields.ads @@ -680,6 +680,7 @@ package Gen_IL.Fields is Is_Checked_Ghost_Entity, Is_Child_Unit, Is_Class_Wide_Equivalent_Type, + Is_Class_Wide_Wrapper, Is_Compilation_Unit, Is_Completely_Hidden, Is_Concurrent_Record_Type, diff --git a/gcc/ada/gen_il-gen-gen_entities.adb b/gcc/ada/gen_il-gen-gen_entities.adb index a000d0e..1fa7f0b 100644 --- a/gcc/ada/gen_il-gen-gen_entities.adb +++ b/gcc/ada/gen_il-gen-gen_entities.adb @@ -126,6 +126,7 @@ begin -- Gen_IL.Gen.Gen_Entities Sm (Is_Character_Type, Flag), Sm (Is_Checked_Ghost_Entity, Flag), Sm (Is_Child_Unit, Flag), + Sm (Is_Class_Wide_Wrapper, Flag), Sm (Is_Class_Wide_Equivalent_Type, Flag), Sm (Is_Compilation_Unit, Flag), Sm (Is_Concurrent_Record_Type, Flag), diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb index 70ad21c..494ec64 100644 --- a/gcc/ada/sem_ch8.adb +++ b/gcc/ada/sem_ch8.adb @@ -2539,8 +2539,8 @@ package body Sem_Ch8 is and then Is_Class_Wide_Type (Get_Instance_Of (Etype (Formal))) then Formal_Typ := Etype (Formal); - Actual_Typ := Get_Instance_Of (Formal_Typ); - Root_Typ := Etype (Actual_Typ); + Actual_Typ := Base_Type (Get_Instance_Of (Formal_Typ)); + Root_Typ := Root_Type (Actual_Typ); exit; end if; @@ -2590,6 +2590,15 @@ package body Sem_Ch8 is elsif CW_Prim_Op = Root_Prim_Op then Prim_Op := Root_Prim_Op; + -- The two subprograms are legal but the class-wide subprogram is + -- a class-wide wrapper built for a previous instantiation; the + -- wrapper has precedence. + + elsif Present (Alias (CW_Prim_Op)) + and then Is_Class_Wide_Wrapper (Ultimate_Alias (CW_Prim_Op)) + then + Prim_Op := CW_Prim_Op; + -- Otherwise both candidate subprograms are user-defined and -- ambiguous. @@ -2688,6 +2697,8 @@ package body Sem_Ch8 is Set_Corresponding_Body (Spec_Decl, Defining_Entity (Body_Decl)); end if; + Set_Is_Class_Wide_Wrapper (Wrap_Id); + -- If the operator carries an Eliminated pragma, indicate that the -- wrapper is also to be eliminated, to prevent spurious error when -- using gnatelim on programs that include box-initialization of |