aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJustin Squirek <squirek@adacore.com>2021-01-15 10:59:49 -0500
committerPierre-Marie de Rodat <derodat@adacore.com>2021-05-06 03:51:30 -0400
commit55b93bbc2158203b776bf516cba0117208e2f649 (patch)
tree0ade836a3f911c0155d01c80876c112ae9540d06 /gcc
parent5413faaec7a2f4a9501361aabd6350f858a9b691 (diff)
downloadgcc-55b93bbc2158203b776bf516cba0117208e2f649.zip
gcc-55b93bbc2158203b776bf516cba0117208e2f649.tar.gz
gcc-55b93bbc2158203b776bf516cba0117208e2f649.tar.bz2
[Ada] Spurious constraint error on conversion of access types
gcc/ada/ * checks.adb (Make_Discriminant_Constraint_Check): Add check for null when the type being converted is an access type.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/checks.adb14
1 files changed, 14 insertions, 0 deletions
diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index a4ad4e6..6487944 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -3658,6 +3658,20 @@ package body Checks is
Cond := Build_Discriminant_Checks (Expr, Expr_Type);
Set_Discriminant_Constraint (Expr_Type, Old_Constraints);
+ -- Conversion between access types requires that we check for null
+ -- before checking discriminants.
+
+ if Is_Access_Type (Etype (Expr)) then
+ Cond := Make_And_Then (Loc,
+ Left_Opnd =>
+ Make_Op_Ne (Loc,
+ Left_Opnd =>
+ Duplicate_Subexpr_No_Checks
+ (Expr, Name_Req => True),
+ Right_Opnd => Make_Null (Loc)),
+ Right_Opnd => Cond);
+ end if;
+
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Condition => Cond,