diff options
author | Ed Schonberg <schonberg@adacore.com> | 2005-03-15 17:01:19 +0100 |
---|---|---|
committer | Arnaud Charlet <charlet@gcc.gnu.org> | 2005-03-15 17:01:19 +0100 |
commit | b7cdaf8d70992dc69fb276e86e8fe75d15ed7b0b (patch) | |
tree | 7fa4caa36aa305bfbec9158228357a6d5641d9aa /gcc | |
parent | a877ccc41ac01335c0915b2ed9215941e24f96a1 (diff) | |
download | gcc-b7cdaf8d70992dc69fb276e86e8fe75d15ed7b0b.zip gcc-b7cdaf8d70992dc69fb276e86e8fe75d15ed7b0b.tar.gz gcc-b7cdaf8d70992dc69fb276e86e8fe75d15ed7b0b.tar.bz2 |
exp_intr.adb (Expand_Unc_Conversion): As a target type...
2005-03-08 Ed Schonberg <schonberg@adacore.com>
* exp_intr.adb (Expand_Unc_Conversion): As a target type, use the type
that appears in the instantiation rather than the internal subtype
generated in the wrapper package, to avoid anomalies in gigi when the
target is derived from a private type whose full view is an access type.
From-SVN: r96495
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/exp_intr.adb | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/gcc/ada/exp_intr.adb b/gcc/ada/exp_intr.adb index 8f41704..1efd42b 100644 --- a/gcc/ada/exp_intr.adb +++ b/gcc/ada/exp_intr.adb @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2004 Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2005 Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -479,6 +479,7 @@ package body Exp_Intr is Func : constant Entity_Id := Entity (Name (N)); Conv : Node_Id; Ftyp : Entity_Id; + Ttyp : Entity_Id; begin -- Rewrite as unchecked conversion node. Note that we must convert @@ -500,12 +501,33 @@ package body Exp_Intr is Analyze_And_Resolve (Conv); end if; + -- The instantiation of Unchecked_Conversion creates a wrapper package, + -- and the target type is declared as a subtype of the actual. Recover + -- the actual, which is the subtype indic. in the subtype declaration + -- for the target type. This is semantically correct, and avoids + -- anomalies with access subtypes. For entities, leave type as is. + -- We do the analysis here, because we do not want the compiler -- to try to optimize or otherwise reorganize the unchecked -- conversion node. - Rewrite (N, Unchecked_Convert_To (Etype (E), Conv)); - Set_Etype (N, Etype (E)); + Ttyp := Etype (E); + + if Is_Entity_Name (Conv) then + null; + + elsif Nkind (Parent (Ttyp)) = N_Subtype_Declaration then + Ttyp := Entity (Subtype_Indication (Parent (Etype (E)))); + + elsif Is_Itype (Ttyp) then + Ttyp := + Entity (Subtype_Indication (Associated_Node_For_Itype (Ttyp))); + else + raise Program_Error; + end if; + + Rewrite (N, Unchecked_Convert_To (Ttyp, Conv)); + Set_Etype (N, Ttyp); Set_Analyzed (N); if Nkind (N) = N_Unchecked_Type_Conversion then |