authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-08 10:54:05-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-08 10:54:05-05:00
log76d0e49e612d661b57b795cd81f5ba06dc26ceca
treed4b4bc124da5cf8b3e7314a2729a0d051a51279c
parente4bc8d22c2f518353d31d8c99de8d35e5ead0c67

fix unable to eval const expr test case


2 files changed, 4 insertions(+), 2 deletions(-)

src/ir.cpp+3-1
...@@ -5266,7 +5266,9 @@ static IrInstruction *ir_exec_const_result(IrExecutable *exec) {...@@ -5266,7 +5266,9 @@ static IrInstruction *ir_exec_const_result(IrExecutable *exec) {
5266 if (instruction->id == IrInstructionIdReturn) {5266 if (instruction->id == IrInstructionIdReturn) {
5267 IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction;5267 IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction;
5268 IrInstruction *value = ret_inst->value;5268 IrInstruction *value = ret_inst->value;
5269 assert(value->value.special != ConstValSpecialRuntime);5269 if (value->value.special == ConstValSpecialRuntime) {
5270 return nullptr;
5271 }
5270 return value;5272 return value;
5271 } else if (ir_has_side_effects(instruction)) {5273 } else if (ir_has_side_effects(instruction)) {
5272 return nullptr;5274 return nullptr;
test/run_tests.cpp+1-1
...@@ -1128,7 +1128,7 @@ const Foo = struct {...@@ -1128,7 +1128,7 @@ const Foo = struct {
1128};1128};
1129var global_var: usize = 1;1129var global_var: usize = 1;
1130fn get() -> usize { global_var }1130fn get() -> usize { global_var }
1131 )SOURCE", 1, ".tmp_source.zig:3:9: error: unable to evaluate constant expression");1131 )SOURCE", 1, ".tmp_source.zig:3:12: error: unable to evaluate constant expression");
11321132
11331133
1134 add_compile_fail_case("unnecessary if statement", R"SOURCE(1134 add_compile_fail_case("unnecessary if statement", R"SOURCE(