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  <schonb...@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.

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;

Reply via email to