From 356424916ced599852e2c38265eebe7a1fc1637d Mon Sep 17 00:00:00 2001 From: Josh Wolfe Date: Wed, 12 Apr 2017 22:18:56 -0700 Subject: block statement lists never get fake expressions instead blocks have a field that encodes whether the last statement ended with a semicolon. --- src/ir.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/ir.cpp') 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; } -- cgit v1.2.3