public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Prevent infinite recursion when there is no expected unit
@ 2021-07-08 13:50 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-07-08 13:50 UTC (permalink / raw)
  To: gcc-patches; +Cc: Piotr Trojanek

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

The comment in Par.Load says "... or we are in big trouble, and abandon
the compilation", but the code merely emitted errors and kept going. Now
it emits errors, flags the problem in the unit table and gives up. Also,
it was wrong for this routine to remove the unit, because the callers
who add entries to the unit table assume those entries to be filled by
the parser and not removed, even when irrecoverable errors happen.

This prevents an infinite recursion that happened when parsing a file
with multiple compilation units and wrong indexes, so the compiler was
scanning unit X, followed its WITH Y clause but instead of unit Y it was
getting unit X and scanned it again and again...

Also, it fixes a crash when compiling a program with subunit that
contains unexpected program unit (previously the compiler only cared
about avoiding such a crash with -gnatc switch).

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

gcc/ada/

	* par-load.adb (Load): Don't remove unit, but flag it as
	erroneous and return.

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

diff --git a/gcc/ada/par-load.adb b/gcc/ada/par-load.adb
--- a/gcc/ada/par-load.adb
+++ b/gcc/ada/par-load.adb
@@ -234,9 +234,10 @@ begin
          Error_Msg ("\\found unit $!", Loc);
       end if;
 
-      --  In both cases, remove the unit so that it is out of the way later
+      --  In both cases, flag the fatal error and give up
 
-      Remove_Unit (Cur_Unum);
+      Set_Fatal_Error (Cur_Unum, Error_Detected);
+      return;
    end if;
 
    --  If current unit is a body, load its corresponding spec



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

only message in thread, other threads:[~2021-07-08 13:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-08 13:50 [Ada] Prevent infinite recursion when there is no expected unit 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).