diff mbox

[Ada] Error recovery in task body

Message ID 20140219102606.GA22043@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Feb. 19, 2014, 10:26 a.m. UTC
This patch fixes a crash in a task body with a single statement missing a
terminating semicolon. The tree can be repaired locally so further compilation
can proceed.

Compiling libthr3.adb must yield:

    libthr3.adb:10:18: missing ";"
    libthr3.adb:13:04: warning: no accept for entry "Test"

---
procedure Libthr3 is
   task type TSK;

   task Driver is
      entry Test;
   end Driver;

   task body TSK is
   begin
      Driver.Test  -- Missing ; gives GNAT BUG DETECTED box
   end TSK;

   task body Driver is
      P : access TSK;
   begin
      P := new TSK;
   end Driver;
begin
   null;
end Libthr3;

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

2014-02-19  Ed Schonberg  <schonberg@adacore.com>

	* par-ch9.adb (P_Task): Add a null statement to produce a
	well-formed task body when due to a previous syntax error the
	statement list is empty.
diff mbox

Patch

Index: par-ch9.adb
===================================================================
--- par-ch9.adb	(revision 207879)
+++ par-ch9.adb	(working copy)
@@ -144,6 +144,17 @@ 
             end if;
 
             Parse_Decls_Begin_End (Task_Node);
+
+            --  The statement list of a task body needs to include at least a
+            --  null statement, so if a parsing error produces an empty list,
+            --  patch it now.
+
+            if
+              No (First (Statements (Handled_Statement_Sequence (Task_Node))))
+            then
+               Set_Statements (Handled_Statement_Sequence (Task_Node),
+                   New_List (Make_Null_Statement (Token_Ptr)));
+            end if;
          end if;
 
          return Task_Node;