commit 6d283bb403b52df5f45b9cb81c6a70c181e45f7c
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Sat Nov 28 10:48:42 2015 +0100
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Sat Nov 28 10:48:42 2015 +0100

    Convert orphaned break and continue into semantic error
    
    In this case it is not needed to recover from the error,
    we only have to emit a diagnosis and we can continue
    without modifying the parser flow.

diff --git a/cc1/stmt.c b/cc1/stmt.c
index c824d29..a16f458 100644
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -163,20 +163,24 @@ static void
 Break(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
 {
        expect(BREAK);
-       if (!lbreak)
-               error("break statement not within loop or switch");
-       emit(OJUMP, lbreak);
-       expect(';');
+       if (!lbreak) {
+               errorp("break statement not within loop or switch");
+       } else {
+               emit(OJUMP, lbreak);
+               expect(';');
+       }
 }
 
 static void
 Continue(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
 {
        expect(CONTINUE);
-       if (!lcont)
-               error("continue statement not within loop");
-       emit(OJUMP, lcont);
-       expect(';');
+       if (!lcont) {
+               errorp("continue statement not within loop");
+       } else {
+               emit(OJUMP, lcont);
+               expect(';');
+       }
 }
 
 static void

Reply via email to