From 924e3532dcdabde43f5b49f1ef1a95656f4e37dc Mon Sep 17 00:00:00 2001 From: Justin Squirek Date: Tue, 9 Jul 2019 07:55:33 +0000 Subject: [PATCH] [Ada] Crash on 'Img attribute This patch fixes and issue whereby applying 'Img to a constant enumerated character type would result in a compiler crash when assertions are enabled and infinite recursion when they are not. 2019-07-09 Justin Squirek gcc/ada/ * sem_eval.adb (Expr_Value_E): Add conditional to correctly handle constant enumerated character types. gcc/testsuite/ * gnat.dg/image1.adb: New testcase. From-SVN: r273292 --- gcc/ada/ChangeLog | 5 +++++ gcc/ada/sem_eval.adb | 10 +++++++++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gnat.dg/image1.adb | 12 ++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gnat.dg/image1.adb diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index cfbdf89a582..524adfd1540 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2019-07-09 Justin Squirek + + * sem_eval.adb (Expr_Value_E): Add conditional to correctly + handle constant enumerated character types. + 2019-07-09 Eric Botcazou * libgnarl/s-osinte__mingw.ads (CRITICAL_SECTION): Use proper diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb index ff3359fb0e2..e140fa72ffb 100644 --- a/gcc/ada/sem_eval.adb +++ b/gcc/ada/sem_eval.adb @@ -4281,7 +4281,15 @@ package body Sem_Eval is return Ent; else pragma Assert (Ekind (Ent) = E_Constant); - return Expr_Value_E (Constant_Value (Ent)); + + -- We may be dealing with a enumerated character type constant, so + -- handle that case here. + + if Nkind (Constant_Value (Ent)) = N_Character_Literal then + return Ent; + else + return Expr_Value_E (Constant_Value (Ent)); + end if; end if; end Expr_Value_E; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fa53a2fc461..d2b1c6b95ca 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-07-09 Justin Squirek + + * gnat.dg/image1.adb: New testcase. + 2019-07-09 Javier Miranda * gnat.dg/rep_clause8.adb: New testcase. diff --git a/gcc/testsuite/gnat.dg/image1.adb b/gcc/testsuite/gnat.dg/image1.adb new file mode 100644 index 00000000000..ae8d6805afb --- /dev/null +++ b/gcc/testsuite/gnat.dg/image1.adb @@ -0,0 +1,12 @@ +-- { dg-do run } + +with Ada.Text_IO; use Ada.Text_IO; +with Ada.Characters.Latin_1; + +procedure Image1 is + Str : String := Ada.Characters.Latin_1.LF'Img; +begin + if Str /= "LF" then + raise Program_Error; + end if; +end Image1; -- 2.30.2