aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorJosh Wolfe <thejoshwolfe@gmail.com>2017-04-23 22:33:06 -0700
committerJosh Wolfe <thejoshwolfe@gmail.com>2017-04-23 22:33:06 -0700
commit08a871f625aaf75ca47ea6bbc6304587c4bbae86 (patch)
treea98353f6fa11344883c4b2256d192d3d6daa8ab3 /src/ir.cpp
parentac7971122dc32f59d82430285e7eaefe5d0d4301 (diff)
downloadzig-08a871f625aaf75ca47ea6bbc6304587c4bbae86.tar.gz
zig-08a871f625aaf75ca47ea6bbc6304587c4bbae86.zip
defer requires expr to be void. closes #341
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 2527fdd803..ba0aba6a1f 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -2051,6 +2051,18 @@ static IrInstruction *ir_build_check_switch_prongs(IrBuilder *irb, Scope *scope,
return &instruction->base;
}
+static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *scope, AstNode *source_node,
+ IrInstruction* statement_value)
+{
+ IrInstructionCheckStatementIsVoid *instruction = ir_build_instruction<IrInstructionCheckStatementIsVoid>(
+ irb, scope, source_node);
+ instruction->statement_value = statement_value;
+
+ ir_ref_instruction(statement_value, irb->current_basic_block);
+
+ return &instruction->base;
+}
+
static IrInstruction *ir_build_test_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
IrInstruction *type_value, TypeTableEntryId type_id)
{
@@ -3139,7 +3151,11 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
(gen_error_defers && defer_kind == ReturnKindError))
{
AstNode *defer_expr_node = defer_node->data.defer.expr;
- ir_gen_node(irb, defer_expr_node, defer_node->data.defer.expr_scope);
+ Scope *defer_expr_scope = defer_node->data.defer.expr_scope;
+ IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);
+ if (defer_expr_value != irb->codegen->invalid_instruction) {
+ ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node, defer_expr_value));
+ }
}
}
@@ -3348,18 +3364,6 @@ static ScopeBlock *find_block_scope(IrExecutable *exec, Scope *scope) {
return nullptr;
}
-static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *scope, AstNode *source_node,
- IrInstruction* statement_value)
-{
- IrInstructionCheckStatementIsVoid *instruction = ir_build_instruction<IrInstructionCheckStatementIsVoid>(
- irb, scope, source_node);
- instruction->statement_value = statement_value;
-
- ir_ref_instruction(statement_value, irb->current_basic_block);
-
- return &instruction->base;
-}
-
static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode *block_node) {
assert(block_node->type == NodeTypeBlock);