diff options
| author | gingerBill <bill@gingerbill.org> | 2020-08-27 11:06:44 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-08-27 11:06:44 +0100 |
| commit | 4daf098a3ae4340daa5a50eee8539ea367ef8875 (patch) | |
| tree | d8c409d8f04a9d9dcb670179c6da0da7eaaa1217 /src/llvm_backend.cpp | |
| parent | d31c63c0ae76115d1b9aa8b5d1f8bf7130e74977 (diff) | |
Fix `defer` on explicit `return` of a procedure with no return values for llvm-api
Diffstat (limited to 'src/llvm_backend.cpp')
| -rw-r--r-- | src/llvm_backend.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index d5b2d9f8d..1d0bb7259 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -4219,6 +4219,9 @@ void lb_build_stmt(lbProcedure *p, Ast *node) { if (return_count == 0) { // No return values + + lb_emit_defer_stmts(p, lbDeferExit_Return, nullptr); + LLVMBuildRetVoid(p->builder); return; } else if (return_count == 1) { @@ -6906,6 +6909,10 @@ void lb_emit_defer_stmts(lbProcedure *p, lbDeferExitKind kind, lbBlock *block) { while (i --> 0) { lbDefer d = p->defer_stmts[i]; + isize prev_context_stack_count = p->context_stack.count; + defer (p->context_stack.count = prev_context_stack_count); + p->context_stack.count = d.context_stack_count; + if (kind == lbDeferExit_Default) { if (p->scope_index == d.scope_index && d.scope_index > 0) { // TODO(bill): Which is correct: > 0 or > 1? |