As part of recent improvements related to discriminant checks, a
regression was introduced in complex cases of generics and use of 'Image
on an expression partially rewritten as a [raise Constraint_Error] node.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* sem_attr.adb (Check_Image_Type): Protect against empty
Image_Type.
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -1466,7 +1466,11 @@ package body Sem_Attr is
procedure Check_Image_Type (Image_Type : Entity_Id) is
begin
+ -- Image_Type may be empty in case of another error detected,
+ -- or if an N_Raise_xxx_Error node is a parent of N.
+
if Ada_Version < Ada_2020
+ and then Present (Image_Type)
and then not Is_Scalar_Type (Image_Type)
then
Error_Msg_Ada_2020_Feature ("nonscalar ''Image", Sloc (P));