From 4600f1d7ff8d712ff8b70d5ee1c3a5f1bf303283 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Sat, 31 Aug 2013 10:48:24 +0200 Subject: [PATCH] more thorough check for whether an ast node starts a new label; closes #121 --- ast.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ast.c b/ast.c index 2f1566b..3531ada 100644 --- a/ast.c +++ b/ast.c @@ -1877,6 +1877,17 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir) return true; } +static bool starts_a_label(ast_expression *ex) +{ + while (ex && ast_istype(ex, ast_block)) { + ast_block *b = (ast_block*)ex; + ex = b->exprs[0]; + } + if (!ex) + return false; + return ast_istype(ex, ast_label); +} + /* Note, you will not see ast_block_codegen generate ir_blocks. * To the AST and the IR, blocks are 2 different things. * In the AST it represents a block of code, usually enclosed in @@ -1922,7 +1933,7 @@ bool ast_block_codegen(ast_block *self, ast_function *func, bool lvalue, ir_valu for (i = 0; i < vec_size(self->exprs); ++i) { ast_expression_codegen *gen; - if (func->curblock->final && !ast_istype(self->exprs[i], ast_label)) { + if (func->curblock->final && !starts_a_label(self->exprs[i])) { if (compile_warning(ast_ctx(self->exprs[i]), WARN_UNREACHABLE_CODE, "unreachable statement")) return false; continue; -- 2.39.2