aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorJosh Wolfe <thejoshwolfe@gmail.com>2017-04-12 22:18:56 -0700
committerJosh Wolfe <thejoshwolfe@gmail.com>2017-04-12 23:22:32 -0700
commit356424916ced599852e2c38265eebe7a1fc1637d (patch)
tree2bec2154f1e4bbb93b0f9d5e959aaf491240ccd0 /src/ir.cpp
parent919910312d7d25fe8f894adbc9ff8a449ac26281 (diff)
downloadzig-356424916ced599852e2c38265eebe7a1fc1637d.tar.gz
zig-356424916ced599852e2c38265eebe7a1fc1637d.zip
block statement lists never get fake expressions
instead blocks have a field that encodes whether the last statement ended with a semicolon.
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 2af3f1d0b3..e334428b3c 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -3378,6 +3378,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
// a label is an entry point
is_continuation_unreachable = false;
+ return_value = nullptr;
continue;
}
@@ -3406,7 +3407,8 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
child_scope = decl_var_instruction->var->child_scope;
} else {
// label, defer, variable declaration will never be the last statement
- if (i == block_node->data.block.statements.length - 1) {
+ if (block_node->data.block.last_statement_is_result_expression &&
+ i == block_node->data.block.statements.length - 1) {
// this is the result value statement
return_value = statement_value;
} else {
@@ -3422,13 +3424,18 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
}
}
- assert(return_value != nullptr);
-
if (!is_continuation_unreachable) {
// control flow falls out of block
+
+ if (!block_node->data.block.last_statement_is_result_expression) {
+ assert(return_value == nullptr);
+ return_value = ir_mark_gen(ir_build_const_void(irb, child_scope, block_node));
+ }
+
ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false, false);
}
+ assert(return_value != nullptr);
return return_value;
}