authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-11 00:36:03-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-11 00:36:03-04:00
logb053a655734a35405f97818d1586d524f6b003b5
treef19d38621999de0d862b11a1db59e656b756fcc6
parent7411a88d5f8109ced238cf14205ae36575f02f21
signature Commit is signed but in an unrecognized format.

fix comptime variables


1 files changed, 8 insertions(+), 4 deletions(-)

src/ir.cpp+8-4
......@@ -5771,8 +5771,8 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
57715771 bool is_const = variable_declaration->is_const;
57725772 bool is_extern = variable_declaration->is_extern;
57735773
5774 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node,
5775 ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime);
5774 bool is_comptime_scalar = ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime;
5775 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, is_comptime_scalar);
57765776 ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol,
57775777 is_const, is_const, is_shadowable, is_comptime);
57785778 // we detect IrInstructionIdDeclVarSrc in gen_block to make sure the next node
......@@ -5806,11 +5806,15 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
58065806 ResultLocVar *result_loc_var = create_var_result_loc(alloca, var);
58075807 ResultLoc *init_result_loc = (type_instruction == nullptr) ? &result_loc_var->base : nullptr;
58085808
5809 Scope *init_scope = is_comptime_scalar ?
5810 create_comptime_scope(irb->codegen, variable_declaration->expr, scope) : scope;
5811
58095812 // Temporarily set the name of the IrExecutable to the VariableDeclaration
58105813 // so that the struct or enum from the init expression inherits the name.
58115814 Buf *old_exec_name = irb->exec->name;
58125815 irb->exec->name = variable_declaration->symbol;
5813 IrInstruction *init_value = ir_gen_node_extra(irb, variable_declaration->expr, scope, LValNone, init_result_loc);
5816 IrInstruction *init_value = ir_gen_node_extra(irb, variable_declaration->expr, init_scope,
5817 LValNone, init_result_loc);
58145818 irb->exec->name = old_exec_name;
58155819
58165820 if (init_value == irb->codegen->invalid_instruction)
......@@ -8029,7 +8033,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
80298033 case NodeTypeContainerInitExpr:
80308034 return ir_gen_container_init_expr(irb, scope, node, lval, result_loc);
80318035 case NodeTypeVariableDeclaration:
8032 return ir_lval_wrap(irb, scope, ir_gen_var_decl(irb, scope, node), lval, result_loc);
8036 return ir_gen_var_decl(irb, scope, node);
80338037 case NodeTypeWhileExpr:
80348038 return ir_gen_while_expr(irb, scope, node, lval, result_loc);
80358039 case NodeTypeForExpr: