This fixes an error recovery issue, whereby the compilation of a string 
concatenation with an illegal character constant hangs.

Tested on x86-64/Linux, applied on the mainline and 15 branch.


2025-06-28  Eric Botcazou  <ebotca...@adacore.com>

        PR ada/120854
        * sem_eval.adb (Get_String_Val): Be prepared for an integer literal
        after a serious error is detected, and raise PE on other nodes.


2025-06-28  Eric Botcazou  <ebotca...@adacore.com>

        * gnat.dg/concat6.adb: New test.

-- 
Eric Botcazou
diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb
index fcab3e79d33..2d64d845ae2 100644
--- a/gcc/ada/sem_eval.adb
+++ b/gcc/ada/sem_eval.adb
@@ -5287,9 +5287,16 @@ package body Sem_Eval is
    begin
       if Nkind (N) in N_String_Literal | N_Character_Literal then
          return N;
-      else
-         pragma Assert (Is_Entity_Name (N));
+      elsif Is_Entity_Name (N) then
          return Get_String_Val (Constant_Value (Entity (N)));
+      elsif Nkind (N) = N_Integer_Literal then
+         pragma Assert (Serious_Errors_Detected /= 0);
+         return
+           Make_Character_Literal (Sloc (N),
+             Chars              => Error_Name,
+             Char_Literal_Value => Intval (N));
+      else
+         raise Program_Error;
       end if;
    end Get_String_Val;
 
-- { dg-do compile }

with Ada.Text_IO; use Ada.Text_IO;

procedure Concat6 is
  C : constant character := 16#00#; -- { dg-error "expected type|found type" }
begin
  Put_Line ("Test " & C);
end;

Reply via email to