diff mbox series

[Ada] Fix evaluation of Enum_Rep applied to imported constant

Message ID 20200706113855.GA135551@adacore.com
State New
Headers show
Series [Ada] Fix evaluation of Enum_Rep applied to imported constant | expand

Commit Message

Pierre-Marie de Rodat July 6, 2020, 11:38 a.m. UTC
Fixes an illegal call to Compile_Time_Known_Value with Empty parameter,
which is now reported as a crash with switch -gnatdk. This is clearly a
corner case; in preparation for a cleanup of some dubious code for
Enum_Rep attribute.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* sem_attr.adb (Eval_Attribute): Check if constant has an
	initialization expression.
diff mbox series

Patch

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
@@ -7834,6 +7834,8 @@  package body Sem_Attr is
                        (Ekind (Entity (Enum_Expr)) = E_Constant
                           and then Nkind (Parent (Entity (Enum_Expr))) =
                                      N_Object_Declaration
+                          and then Present
+                                     (Expression (Parent (Entity (P))))
                           and then Compile_Time_Known_Value
                                      (Expression (Parent (Entity (P))))))
                   then