Commit 924e3532 by Justin Squirek Committed by Pierre-Marie de Rodat

[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
parent 18934a8d
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> 2019-07-09 Eric Botcazou <ebotcazou@adacore.com>
* libgnarl/s-osinte__mingw.ads (CRITICAL_SECTION): Use proper * libgnarl/s-osinte__mingw.ads (CRITICAL_SECTION): Use proper
......
...@@ -4281,8 +4281,16 @@ package body Sem_Eval is ...@@ -4281,8 +4281,16 @@ package body Sem_Eval is
return Ent; return Ent;
else else
pragma Assert (Ekind (Ent) = E_Constant); pragma Assert (Ekind (Ent) = E_Constant);
-- 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)); return Expr_Value_E (Constant_Value (Ent));
end if; end if;
end if;
end Expr_Value_E; end Expr_Value_E;
------------------ ------------------
......
2019-07-09 Justin Squirek <squirek@adacore.com>
* gnat.dg/image1.adb: New testcase.
2019-07-09 Javier Miranda <miranda@adacore.com> 2019-07-09 Javier Miranda <miranda@adacore.com>
* gnat.dg/rep_clause8.adb: New testcase. * gnat.dg/rep_clause8.adb: New testcase.
......
-- { 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;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment