ref: 6d283bb403b52df5f45b9cb81c6a70c181e45f7c
parent: 9c337dec526ba7b485ba66957f196249afa82922
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Nov 28 05:48:42 EST 2015
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.
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -163,10 +163,12 @@
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
@@ -173,10 +175,12 @@
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
--
⑨