mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Fix #1344
This commit is contained in:
@@ -58,6 +58,30 @@ bool contains_deferred_call(Ast *node) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ast *last_stmt_blocking_in_list(Slice<Ast *> const &stmts) {
|
||||||
|
for_array(i, stmts) {
|
||||||
|
Ast *n = stmts[i];
|
||||||
|
switch (n->kind) {
|
||||||
|
case Ast_ReturnStmt:
|
||||||
|
return n;
|
||||||
|
case Ast_BranchStmt:
|
||||||
|
return n;
|
||||||
|
case Ast_ExprStmt:
|
||||||
|
if (is_diverging_stmt(n)) {
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Ast_BlockStmt:
|
||||||
|
n = last_stmt_blocking_in_list(n->BlockStmt.stmts);
|
||||||
|
if (n != nullptr) {
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void check_stmt_list(CheckerContext *ctx, Slice<Ast *> const &stmts, u32 flags) {
|
void check_stmt_list(CheckerContext *ctx, Slice<Ast *> const &stmts, u32 flags) {
|
||||||
if (stmts.count == 0) {
|
if (stmts.count == 0) {
|
||||||
return;
|
return;
|
||||||
@@ -102,6 +126,7 @@ void check_stmt_list(CheckerContext *ctx, Slice<Ast *> const &stmts, u32 flags)
|
|||||||
check_stmt(ctx, n, new_flags);
|
check_stmt(ctx, n, new_flags);
|
||||||
|
|
||||||
if (i+1 < max_non_constant_declaration) {
|
if (i+1 < max_non_constant_declaration) {
|
||||||
|
never_executed_error:;
|
||||||
switch (n->kind) {
|
switch (n->kind) {
|
||||||
case Ast_ReturnStmt:
|
case Ast_ReturnStmt:
|
||||||
error(n, "Statements after this 'return' are never executed");
|
error(n, "Statements after this 'return' are never executed");
|
||||||
@@ -116,6 +141,13 @@ void check_stmt_list(CheckerContext *ctx, Slice<Ast *> const &stmts, u32 flags)
|
|||||||
error(n, "Statements after a diverging procedure call are never executed");
|
error(n, "Statements after a diverging procedure call are never executed");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Ast_BlockStmt:
|
||||||
|
n = last_stmt_blocking_in_list(n->BlockStmt.stmts);
|
||||||
|
if (n != nullptr) {
|
||||||
|
goto never_executed_error;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else if (i+1 == max_non_constant_declaration) {
|
} else if (i+1 == max_non_constant_declaration) {
|
||||||
if (is_diverging_stmt(n)) {
|
if (is_diverging_stmt(n)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user