}
+#define MAX_FALLTHROUGH_SWITCH_DEPTH 32
+
+static int fallthrough_switch_depth = 0;
+static int fallthrough_case_active[MAX_FALLTHROUGH_SWITCH_DEPTH];
+static int fallthrough_case_has_statement[MAX_FALLTHROUGH_SWITCH_DEPTH];
+
+static int fallthrough_case_ends_control_flow[MAX_FALLTHROUGH_SWITCH_DEPTH];
+
static int current_function_has_return_statement = 0;
static int statement_ends_control_flow = 0;
ensure_block_stack_allocated (block_stack_start, &block_stack_bytes, &block_stack_emitted);
}
+ if (fallthrough_switch_depth > 0 && fallthrough_case_active[fallthrough_switch_depth - 1]) {
+
+ fallthrough_case_has_statement[fallthrough_switch_depth - 1] = 1;
+ fallthrough_case_ends_control_flow[fallthrough_switch_depth - 1] = 0;
+
+ }
+
continue;
}
}
- parse_statement ();
+ {
+
+ enum token_kind statement_kind = tok.kind;
+ parse_statement ();
+
+ if (fallthrough_switch_depth > 0 && statement_kind != TOK_CASE && statement_kind != TOK_DEFAULT && fallthrough_case_active[fallthrough_switch_depth - 1]) {
+
+ fallthrough_case_has_statement[fallthrough_switch_depth - 1] = 1;
+ fallthrough_case_ends_control_flow[fallthrough_switch_depth - 1] = statement_ends_control_flow;
+
+ }
+
+ }
if (statement_ends_control_flow) {
block_ends_control_flow = 1;
long old_break_cleanup_base;
long old_continue_cleanup_base;
+ int fallthrough_tracking_pushed = 0;
int saved_ends_control_flow;
FILE *saved_ofp;
}
+ if (fallthrough_switch_depth < MAX_FALLTHROUGH_SWITCH_DEPTH) {
+
+ fallthrough_case_active[fallthrough_switch_depth] = 0;
+ fallthrough_case_has_statement[fallthrough_switch_depth] = 0;
+ fallthrough_case_ends_control_flow[fallthrough_switch_depth] = 0;
+ fallthrough_switch_depth++;
+ fallthrough_tracking_pushed = 1;
+
+ }
+
parse_statement ();
saved_ends_control_flow = statement_ends_control_flow;
+ if (fallthrough_tracking_pushed) {
+ fallthrough_switch_depth--;
+ }
+
if (body_tmp) {
body_text = read_tmp_file_text (body_tmp);
const char *case_start = tok.start;
const char *case_caret = tok.caret;
+ if (fallthrough_switch_depth > 0) {
+
+ int fall_index = fallthrough_switch_depth - 1;
+
+ if ((state->warn & WARN_FALLTHROUGH) && fallthrough_case_active[fall_index] && fallthrough_case_has_statement[fall_index] && !fallthrough_case_ends_control_flow[fall_index]) {
+ report_line_at (get_filename (), case_line, REPORT_WARNING, case_start, case_caret, "this case may be reached by fallthrough");
+ }
+
+ fallthrough_case_active[fall_index] = 1;
+ fallthrough_case_has_statement[fall_index] = 0;
+ fallthrough_case_ends_control_flow[fall_index] = 0;
+
+ }
+
get_token ();
value = const_from_current_case_expr ();
const char *default_start = tok.start;
const char *default_caret = tok.caret;
+ if (fallthrough_switch_depth > 0) {
+
+ int fall_index = fallthrough_switch_depth - 1;
+
+ if ((state->warn & WARN_FALLTHROUGH) && fallthrough_case_active[fall_index] && fallthrough_case_has_statement[fall_index] && !fallthrough_case_ends_control_flow[fall_index]) {
+ report_line_at (get_filename (), default_line, REPORT_WARNING, default_start, default_caret, "this case may be reached by fallthrough");
+ }
+
+ fallthrough_case_active[fall_index] = 1;
+ fallthrough_case_has_statement[fall_index] = 0;
+ fallthrough_case_ends_control_flow[fall_index] = 0;
+
+ }
+
get_token ();
set_switch_default_label (default_line, default_start, default_caret);
}
+#define MAX_FALLTHROUGH_SWITCH_DEPTH 32
+
+static int fallthrough_switch_depth = 0;
+static int fallthrough_case_active[MAX_FALLTHROUGH_SWITCH_DEPTH];
+static int fallthrough_case_has_statement[MAX_FALLTHROUGH_SWITCH_DEPTH];
+static int fallthrough_case_ends_control_flow[MAX_FALLTHROUGH_SWITCH_DEPTH];
+
static int current_function_has_return_statement = 0;
static int statement_ends_control_flow = 0;
ensure_block_stack_allocated (block_stack_start, &block_stack_bytes, &block_stack_emitted);
}
+ if (fallthrough_switch_depth > 0 && fallthrough_case_active[fallthrough_switch_depth - 1]) {
+
+ fallthrough_case_has_statement[fallthrough_switch_depth - 1] = 1;
+ fallthrough_case_ends_control_flow[fallthrough_switch_depth - 1] = 0;
+
+ }
+
continue;
}
}
- parse_statement ();
+ {
+
+ enum token_kind statement_kind = tok.kind;
+ parse_statement ();
+
+ if (fallthrough_switch_depth > 0 && statement_kind != TOK_CASE && statement_kind != TOK_DEFAULT && fallthrough_case_active[fallthrough_switch_depth - 1]) {
+
+ fallthrough_case_has_statement[fallthrough_switch_depth - 1] = 1;
+ fallthrough_case_ends_control_flow[fallthrough_switch_depth - 1] = statement_ends_control_flow;
+
+ }
+
+ }
if (statement_ends_control_flow) {
block_ends_control_flow = 1;
long old_break_cleanup_base;
long old_continue_cleanup_base;
+ int fallthrough_tracking_pushed = 0;
int saved_ends_control_flow;
FILE *saved_ofp;
}
+ if (fallthrough_switch_depth < MAX_FALLTHROUGH_SWITCH_DEPTH) {
+
+ fallthrough_case_active[fallthrough_switch_depth] = 0;
+ fallthrough_case_has_statement[fallthrough_switch_depth] = 0;
+ fallthrough_case_ends_control_flow[fallthrough_switch_depth] = 0;
+ fallthrough_switch_depth++;
+ fallthrough_tracking_pushed = 1;
+
+ }
+
parse_statement ();
saved_ends_control_flow = statement_ends_control_flow;
+ if (fallthrough_tracking_pushed) {
+ fallthrough_switch_depth--;
+ }
+
if (body_tmp) {
body_text = read_tmp_file_text (body_tmp);
const char *case_start = tok.start;
const char *case_caret = tok.caret;
+ if (fallthrough_switch_depth > 0) {
+
+ int fall_index = fallthrough_switch_depth - 1;
+
+ if ((state->warn & WARN_FALLTHROUGH) && fallthrough_case_active[fall_index] && fallthrough_case_has_statement[fall_index] && !fallthrough_case_ends_control_flow[fall_index]) {
+ report_line_at (get_filename (), case_line, REPORT_WARNING, case_start, case_caret, "this case may be reached by fallthrough");
+ }
+
+ fallthrough_case_active[fall_index] = 1;
+ fallthrough_case_has_statement[fall_index] = 0;
+ fallthrough_case_ends_control_flow[fall_index] = 0;
+
+ }
+
get_token ();
value = const_from_current_case_expr ();
const char *default_start = tok.start;
const char *default_caret = tok.caret;
+ if (fallthrough_switch_depth > 0) {
+
+ int fall_index = fallthrough_switch_depth - 1;
+
+ if ((state->warn & WARN_FALLTHROUGH) && fallthrough_case_active[fall_index] && fallthrough_case_has_statement[fall_index] && !fallthrough_case_ends_control_flow[fall_index]) {
+ report_line_at (get_filename (), default_line, REPORT_WARNING, default_start, default_caret, "this case may be reached by fallthrough");
+ }
+
+ fallthrough_case_active[fall_index] = 1;
+ fallthrough_case_has_statement[fall_index] = 0;
+ fallthrough_case_ends_control_flow[fall_index] = 0;
+
+ }
+
get_token ();
set_switch_default_label (default_line, default_start, default_caret);
if (!get_line ()) {
- free ((char *) get_filename ());
-
if ((history = vec_pop (&vec_history))) {
+ free ((char *) get_filename ());
state->ifp = history->ifp;
new_line_number = history->new_line_number;