aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsquirek <squirek@adacore.com>2024-08-13 11:35:06 +0000
committerMarc Poulhiès <dkm@gcc.gnu.org>2024-11-12 14:00:48 +0100
commit300557bd6d0145cb0210942d80f866cc3b057695 (patch)
tree083e27879533e0871214f0ddf4762f9475935d61
parent093894adbdf0638a494257bfe4bc42eb7ad13f6b (diff)
downloadgcc-300557bd6d0145cb0210942d80f866cc3b057695.zip
gcc-300557bd6d0145cb0210942d80f866cc3b057695.tar.gz
gcc-300557bd6d0145cb0210942d80f866cc3b057695.tar.bz2
ada: Missing runtime tag check on mutably tagged objects
This patch fixes an issue in the compiler whereby assigning to a non-existant mutably tagged object component failed to result in the expected run-time exception. gcc/ada/ChangeLog: * exp_ch4.adb (Expand_N_Type_Conversion): Add special runtime check generation for mutably tagged objects.
-rw-r--r--gcc/ada/exp_ch4.adb32
1 files changed, 30 insertions, 2 deletions
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 381c9f8..c16e09d 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -11684,6 +11684,34 @@ package body Exp_Ch4 is
end if;
end if;
+ -- Generate a tag check for view conversions of mutably tagged objects,
+ -- which are special in nature and require selecting the tag component
+ -- from the class-wide equivalent type.
+
+ -- Possibly this could be combined with the logic below for better code
+ -- reuse ???
+
+ if Is_View_Conversion (N)
+ and then Is_Variable (Operand)
+ and then Is_Class_Wide_Equivalent_Type (Etype (Operand))
+ then
+ -- Generate:
+ -- [Constraint_Error when Operand.Tag /= Root_Type]
+
+ Insert_Action (N,
+ Make_Raise_Constraint_Error (Loc,
+ Condition =>
+ Make_Op_Ne (Loc,
+ Left_Opnd =>
+ Make_Selected_Component (Loc,
+ Prefix => Duplicate_Subexpr_No_Checks (Operand),
+ Selector_Name => Make_Identifier (Loc, Name_uTag)),
+ Right_Opnd =>
+ Make_Attribute_Reference (Loc,
+ Prefix => New_Occurrence_Of (Target_Type, Loc),
+ Attribute_Name => Name_Tag)),
+ Reason => CE_Tag_Check_Failed));
+
-- Case of conversions of tagged types and access to tagged types
-- When needed, that is to say when the expression is class-wide, Add
@@ -11699,8 +11727,8 @@ package body Exp_Ch4 is
-- and then Operand.all not in
-- Designated_Type (Target_Type)'Class]
- if (Is_Access_Type (Target_Type)
- and then Is_Tagged_Type (Designated_Type (Target_Type)))
+ elsif (Is_Access_Type (Target_Type)
+ and then Is_Tagged_Type (Designated_Type (Target_Type)))
or else Is_Tagged_Type (Target_Type)
then
-- Do not do any expansion in the access type case if the parent is a