https://gcc.gnu.org/g:0788add46a172b7b1c565fafdef80979be3dc2a6

commit r16-1761-g0788add46a172b7b1c565fafdef80979be3dc2a6
Author: Eric Botcazou <ebotca...@adacore.com>
Date:   Sat Jun 28 17:42:26 2025 +0200

    Fix compilation of concatenation with illegal character constant
    
    This fixes an error recovery issue, whereby the compilation of a string
    concatenation with an illegal character constant hangs.
    
    gcc/ada/
            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.
    gcc/testsuite/
            * gnat.dg/concat6.adb: New test.

Diff:
---
 gcc/ada/sem_eval.adb              | 11 +++++++++--
 gcc/testsuite/gnat.dg/concat6.adb |  9 +++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb
index fcab3e79d332..2d64d845ae24 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;
 
diff --git a/gcc/testsuite/gnat.dg/concat6.adb 
b/gcc/testsuite/gnat.dg/concat6.adb
new file mode 100644
index 000000000000..015be56bcb2b
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/concat6.adb
@@ -0,0 +1,9 @@
+-- { 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