aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-04-09 17:26:04 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-04-09 17:26:04 -0700
commit707131e37b2ee384d46c26ada83f3c83edf7278d (patch)
tree9be432cadba02d1814997072029dd16705a5c740 /src
parent7eb6af1d3e92510cb558d43ac80c45964f183bb7 (diff)
downloadzig-707131e37b2ee384d46c26ada83f3c83edf7278d.tar.gz
zig-707131e37b2ee384d46c26ada83f3c83edf7278d.zip
goto: jumping out of scope runs defers
see #44
Diffstat (limited to 'src')
-rw-r--r--src/codegen.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 89bfc4d294..e2c3b6667b 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -2724,6 +2724,12 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) {
static LLVMValueRef gen_goto(CodeGen *g, AstNode *node) {
assert(node->type == NodeTypeGoto);
+ // generate defers for blocks that we exit
+ LabelTableEntry *label = node->data.goto_expr.label_entry;
+ BlockContext *this_context = node->block_context;
+ BlockContext *target_context = label->decl_node->block_context;
+ gen_defers_for_block(g, this_context, target_context, false, false);
+
add_debug_source_node(g, node);
LLVMBuildBr(g->builder, node->data.goto_expr.label_entry->basic_block);
return nullptr;