* [Ada] Spurious constraint error on conversion of access types
@ 2021-05-06 7:58 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-05-06 7:58 UTC (permalink / raw)
To: gcc-patches; +Cc: Justin Squirek
[-- Attachment #1: Type: text/plain, Size: 381 bytes --]
This patch fixes an error in the compiler whereby a spurious constraint
error is raised at runtime on type conversions between
access-to-discriminanted types when the object being converted is null.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* checks.adb (Make_Discriminant_Constraint_Check): Add check for
null when the type being converted is an access type.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 962 bytes --]
diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
--- 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,
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-05-06 7:58 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-06 7:58 [Ada] Spurious constraint error on conversion of access types Pierre-Marie de Rodat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).