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
signaturelock-open 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...@@ -5771,8 +5771,8 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
5771 bool is_const = variable_declaration->is_const;5771 bool is_const = variable_declaration->is_const;
5772 bool is_extern = variable_declaration->is_extern;5772 bool is_extern = variable_declaration->is_extern;
57735773
5774 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node,5774 bool is_comptime_scalar = ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime;
5775 ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime);5775 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, is_comptime_scalar);
5776 ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol,5776 ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol,
5777 is_const, is_const, is_shadowable, is_comptime);5777 is_const, is_const, is_shadowable, is_comptime);
5778 // we detect IrInstructionIdDeclVarSrc in gen_block to make sure the next node5778 // 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...@@ -5806,11 +5806,15 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
5806 ResultLocVar *result_loc_var = create_var_result_loc(alloca, var);5806 ResultLocVar *result_loc_var = create_var_result_loc(alloca, var);
5807 ResultLoc *init_result_loc = (type_instruction == nullptr) ? &result_loc_var->base : nullptr;5807 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
5809 // Temporarily set the name of the IrExecutable to the VariableDeclaration5812 // Temporarily set the name of the IrExecutable to the VariableDeclaration
5810 // so that the struct or enum from the init expression inherits the name.5813 // so that the struct or enum from the init expression inherits the name.
5811 Buf *old_exec_name = irb->exec->name;5814 Buf *old_exec_name = irb->exec->name;
5812 irb->exec->name = variable_declaration->symbol;5815 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);
5814 irb->exec->name = old_exec_name;5818 irb->exec->name = old_exec_name;
58155819
5816 if (init_value == irb->codegen->invalid_instruction)5820 if (init_value == irb->codegen->invalid_instruction)
...@@ -8029,7 +8033,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -8029,7 +8033,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
8029 case NodeTypeContainerInitExpr:8033 case NodeTypeContainerInitExpr:
8030 return ir_gen_container_init_expr(irb, scope, node, lval, result_loc);8034 return ir_gen_container_init_expr(irb, scope, node, lval, result_loc);
8031 case NodeTypeVariableDeclaration:8035 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);
8033 case NodeTypeWhileExpr:8037 case NodeTypeWhileExpr:
8034 return ir_gen_while_expr(irb, scope, node, lval, result_loc);8038 return ir_gen_while_expr(irb, scope, node, lval, result_loc);
8035 case NodeTypeForExpr:8039 case NodeTypeForExpr: