Patchwork [Ada] Guard against cascaded error when processing deferred config pragmas

login
register
mail settings
Submitter Arnaud Charlet
Date Aug. 6, 2012, 7:59 a.m.
Message ID <20120806075924.GA6120@adacore.com>
Download mbox | patch
Permalink /patch/175290/
State New
Headers show

Comments

Arnaud Charlet - Aug. 6, 2012, 7:59 a.m.
Some configuration pragmas require the presence of a compilation unit context
to be processed. Their analysis is deferred until after the main unit
has been analyzed. However, if that analysis fails for any reason, then the
context may not be correctly established, and the deferred config pragmas
must not be analyzed, because this could cause a compiler crash.

Using a compiler with assertions enabled, the following compilation must
produce the indicated error message (and no bug box):

$ gcc -c illeg.adb
illeg.adb:2:04: declaration expected

package Illeg is
   procedure Proc;
end Illeg;
package body Illeg is
   illegal;
end Illeg;

--  gnat.adc:
pragma Initialize_Scalars;
pragma Restrictions (No_Abort_Statements);
pragma Restrictions (Max_Asynchronous_Select_Nesting => 0);
pragma Restrictions (No_Asynchronous_Control);
pragma Restrictions (No_Dynamic_Priorities);
pragma Interrupt_State (Name => SIGABRT, State => SYSTEM);
pragma Interrupt_State (Name => SIGTERM, State => SYSTEM);
pragma Interrupt_State (Name => SIGPIPE, State => SYSTEM);

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

2012-08-06  Thomas Quinot  <quinot@adacore.com>

	* frontend.adb: Do not attempt to process deferred configuration
	pragmas if the main unit failed to load, to avoid cascaded
	inconsistencies that can lead to a compiler crash.

Patch

Index: frontend.adb
===================================================================
--- frontend.adb	(revision 190155)
+++ frontend.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2012, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -282,6 +282,7 @@ 
    --  a context for their semantic processing.
 
    if Config_Pragmas /= Error_List
+     and then not Fatal_Error (Main_Unit)
      and then Operating_Mode /= Check_Syntax
    then
       --  Pragmas that require some semantic activity, such as