[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  <squirek@adacore.com>

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
This commit is contained in:
Justin Squirek 2019-07-09 07:55:33 +00:00 committed by Pierre-Marie de Rodat
parent 18934a8d0f
commit 924e3532dc
4 changed files with 30 additions and 1 deletions

View file

@ -1,3 +1,8 @@
2019-07-09 Justin Squirek <squirek@adacore.com>
* sem_eval.adb (Expr_Value_E): Add conditional to correctly
handle constant enumerated character types.
2019-07-09 Eric Botcazou <ebotcazou@adacore.com>
* libgnarl/s-osinte__mingw.ads (CRITICAL_SECTION): Use proper

View file

@ -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;

View file

@ -1,3 +1,7 @@
2019-07-09 Justin Squirek <squirek@adacore.com>
* gnat.dg/image1.adb: New testcase.
2019-07-09 Javier Miranda <miranda@adacore.com>
* gnat.dg/rep_clause8.adb: New testcase.

View file

@ -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;