]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix compilation of concatenation with illegal character constant
authorEric Botcazou <ebotcazou@adacore.com>
Sat, 28 Jun 2025 15:42:26 +0000 (17:42 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Sat, 28 Jun 2025 15:44:04 +0000 (17:44 +0200)
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.

gcc/ada/sem_eval.adb
gcc/testsuite/gnat.dg/concat6.adb [new file with mode: 0644]

index fcab3e79d3327f2a5b0194961b9ae351ee7a34da..2d64d845ae24366c75e22fd8ef38826d5acf33b1 100644 (file)
@@ -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 (file)
index 0000000..015be56
--- /dev/null
@@ -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;