[Ada] Crash on function in Ghost subunit
This patch modifies the creation of class-wide subtypes to preserve vital
attributes related to Ghost code. The subtype is created by copying the
contents of a class-wide type into a newly created itype. When the itype
is created within a Ghost region, the act of copying destroys Ghost code
related attributes. As a result, if the now living class-wide subtype is
frozen within an ignored Ghost region, its freeze node is hoisted prior
to the start of the region, howeve the subtype is still eliminated from
the tree.
------------
-- Source --
------------
-- pack.ads
with Ada.Finalization; use Ada.Finalization;
package Pack is
type Ctrl is new Controlled with null record;
function Make_Ctrl return Ctrl;
package Nested with Ghost is
procedure Proc;
end Nested;
end Pack;
-- pack.adb
package body Pack is
function Make_Ctrl return Ctrl is
begin
return Result : Ctrl;
end Make_Ctrl;
package body Nested is separate;
end Pack;
-- pack-nested.adb
separate (Pack)
package body Nested is
procedure Proc is
Res : constant Ctrl'Class := Make_Ctrl;
begin null; end Proc;
end Nested;
-----------------
-- Compilation --
-----------------
$ gcc -c pack.adb
2018-05-24 Hristian Kirtchev <kirtchev@adacore.com>
gcc/ada/
* exp_util.adb (New_Class_Wide_Subtype): Capture and restore relevant
Ghost-related attributes of the class-wide subtype because the copy
clobbers them.
From-SVN: r260653