public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fix crash on pragma Compile_Time_Warning/Error
@ 2021-12-01 10:25 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-12-01 10:25 UTC (permalink / raw)
  To: gcc-patches; +Cc: Bob Duff

[-- Attachment #1: Type: text/plain, Size: 723 bytes --]

This patch fixes a compiler crash that occurs in the following
situation: The file being compiled with's a generic package. The body of
that generic package contains a procedure that does not have a separate
spec (i.e. the procedure body acts as the spec). The procedure body
instantiates another generic, which contains a pragma
Compile_Time_Warning or Compile_Time_Error.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* sem_prag.adb (Process_Compile_Time_Warning_Or_Error): Do not
	follow the Corresponding_Spec pointer if Acts_As_Spec is True,
	because Corresponding_Spec is Empty in that case, so we would
	exit the loop prematurely, and incorrectly think we are not
	inside a generic unit when we are.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 814 bytes --]

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -7827,11 +7827,15 @@ package body Sem_Prag is
 
          if Compile_Time_Known_Value (Arg1x) then
             Validate_Compile_Time_Warning_Or_Error (N, Sloc (Arg1));
+
          else
             while Present (P) and then Nkind (P) not in N_Generic_Declaration
             loop
-               if Nkind (P) in N_Package_Body | N_Subprogram_Body then
-                  P := Corresponding_Spec (P);
+               if (Nkind (P) = N_Subprogram_Body and then not Acts_As_Spec (P))
+                 or else Nkind (P) = N_Package_Body
+               then
+                  P := Parent (Corresponding_Spec (P));
+
                else
                   P := Parent (P);
                end if;



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-01 10:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-01 10:25 [Ada] Fix crash on pragma Compile_Time_Warning/Error 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).