* [Ada] Crash on pragma Compile_Time_Warning with declared string constant
@ 2018-05-22 13:38 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2018-05-22 13:38 UTC (permalink / raw)
To: gcc-patches; +Cc: Ed Schonberg
[-- Attachment #1: Type: text/plain, Size: 871 bytes --]
This patch fixes a compiler abort on a pragma Compile_Time_Warning when its
second argument is a reference to a constsant string (rather than a string
literal or an expression that evaluates to a string literal).
Compiling main.adb must yield:
main.adb:5:33: warning: Good
main.adb:6:33: warning: VALLUE
main.adb:7:33: warning: Test
----
procedure Main is
Value : constant String := "Test";
Switch : constant Boolean := True;
begin
pragma Compile_Time_Warning (Switch, "Good");
pragma Compile_Time_Warning (Switch, "VAL" & "LUE");
pragma Compile_Time_Warning (Switch, value);
null;
end Main;
Tested on x86_64-pc-linux-gnu, committed on trunk
2018-05-22 Ed Schonberg <schonberg@adacore.com>
gcc/ada/
* sem_prag.adb (Process_Compile_Time_Warning_Or_Error): Handle properly
a second argument that is a constant of a given string value.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1043 bytes --]
--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -30359,11 +30359,18 @@ package body Sem_Prag is
if Compile_Time_Known_Value (Arg1x) then
if Is_True (Expr_Value (Arg1x)) then
+
+ -- We have already verified that the second argument is a static
+ -- string expression. Its string value must be retrieved
+ -- explicitly if it is a declared constant, otherwise it has
+ -- been constant-folded previously.
+
declare
Cent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
Pname : constant Name_Id := Pragma_Name_Unmapped (N);
Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
- Str : constant String_Id := Strval (Get_Pragma_Arg (Arg2));
+ Str : constant String_Id :=
+ Strval (Expr_Value_S (Get_Pragma_Arg (Arg2)));
Str_Len : constant Nat := String_Length (Str);
Force : constant Boolean :=
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-05-22 13:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-22 13:38 [Ada] Crash on pragma Compile_Time_Warning with declared string constant Pierre-Marie de Rodat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).