mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-01 04:10:42 +00:00
more thorough check for whether an ast node starts a new label; closes #121
This commit is contained in:
parent
79219ae201
commit
4600f1d7ff
1 changed files with 12 additions and 1 deletions
13
ast.c
13
ast.c
|
@ -1877,6 +1877,17 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
|
||||||
return true;
|
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.
|
/* Note, you will not see ast_block_codegen generate ir_blocks.
|
||||||
* To the AST and the IR, blocks are 2 different things.
|
* To the AST and the IR, blocks are 2 different things.
|
||||||
* In the AST it represents a block of code, usually enclosed in
|
* 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)
|
for (i = 0; i < vec_size(self->exprs); ++i)
|
||||||
{
|
{
|
||||||
ast_expression_codegen *gen;
|
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"))
|
if (compile_warning(ast_ctx(self->exprs[i]), WARN_UNREACHABLE_CODE, "unreachable statement"))
|
||||||
return false;
|
return false;
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue