[Ada] Prevent infinite recursion when there is no expected unit

Pierre-Marie de Rodat derodat@adacore.com
Thu Jul 8 13:50:15 GMT 2021


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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: text/x-diff
Size: 515 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210708/60026292/attachment-0001.bin>


More information about the Gcc-patches mailing list