aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorJavier Miranda <miranda@adacore.com>2024-07-29 10:26:53 +0000
committerMarc Poulhiès <dkm@gcc.gnu.org>2024-08-08 16:28:28 +0200
commit90b3826db603022edcdcea46711d4e4b58aeae12 (patch)
tree3bd7c76b5c8ba63397cb8f2eb64c1acf3f09eb2f /gcc/ada
parent33aca37ebc0c06e9c9240a8a0c13e31a0bcd4efb (diff)
downloadgcc-90b3826db603022edcdcea46711d4e4b58aeae12.zip
gcc-90b3826db603022edcdcea46711d4e4b58aeae12.tar.gz
gcc-90b3826db603022edcdcea46711d4e4b58aeae12.tar.bz2
ada: Finalization_Size raises Constraint_Error
When the attribute Finalization_Size is applied to an interface type object, the compiler-generated code fails at runtime, raising a Constraint_Error exception. gcc/ada/ * exp_attr.adb (Expand_N_Attribute_Reference) <Finalization_Size>: If the prefix is an interface type, generate code to obtain its address and displace it to reference the base of the object.
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/exp_attr.adb25
1 files changed, 24 insertions, 1 deletions
diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index 13c7444..6475308 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -3688,11 +3688,34 @@ package body Exp_Attr is
-- Local variables
- Size : Entity_Id;
+ P_Loc : constant Source_Ptr := Sloc (Pref);
+ Size : Entity_Id;
-- Start of processing for Finalization_Size
begin
+ -- If the prefix is an interface type, generate code to obtain its
+ -- address and displace it to reference the base of the object.
+
+ if Is_Interface (Ptyp) then
+ -- Generate:
+ -- Ptyp!(tag_ptr!($base_address (ptr.all'address)).all)
+
+ Rewrite (Pref,
+ Unchecked_Convert_To (Ptyp,
+ Make_Explicit_Dereference (P_Loc,
+ Unchecked_Convert_To (RTE (RE_Tag_Ptr),
+ Make_Function_Call (P_Loc,
+ Name => New_Occurrence_Of
+ (RTE (RE_Base_Address), P_Loc),
+ Parameter_Associations =>
+ New_List (
+ Make_Attribute_Reference (P_Loc,
+ Prefix => Duplicate_Subexpr (Pref),
+ Attribute_Name => Name_Address)))))));
+ Analyze_And_Resolve (Pref, Ptyp);
+ end if;
+
-- If the prefix is the dereference of an access value subject to
-- pragma No_Heap_Finalization, then no header has been added.