authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-18 17:43:05-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-18 17:43:05-04:00
log79671efd3a5b67e359aa60c66e4007c03342b28e
tree410d812c520924418e326497e5343dd431a37d01
parente27da17ff2cc45c93ab95defd937fd8038751b51
signature Commit is signed but in an unrecognized format.

fix inline loop behavior with variable result loc


2 files changed, 27 insertions(+), 22 deletions(-)

src/ir.cpp+6-1
...@@ -15157,9 +15157,14 @@ static void ir_reset_result(ResultLoc *result_loc) {...@@ -15157,9 +15157,14 @@ static void ir_reset_result(ResultLoc *result_loc) {
15157 }15157 }
15158 break;15158 break;
15159 }15159 }
15160 case ResultLocIdVar: {
15161 IrInstructionAllocaSrc *alloca_src =
15162 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);
15163 alloca_src->base.child = nullptr;
15164 break;
15165 }
15160 case ResultLocIdPeer:15166 case ResultLocIdPeer:
15161 case ResultLocIdNone:15167 case ResultLocIdNone:
15162 case ResultLocIdVar:
15163 case ResultLocIdReturn:15168 case ResultLocIdReturn:
15164 case ResultLocIdInstruction:15169 case ResultLocIdInstruction:
15165 case ResultLocIdBitCast:15170 case ResultLocIdBitCast:
test/stage1/behavior/eval.zig+21-21
...@@ -190,16 +190,16 @@ fn testTryToTrickEvalWithRuntimeIf(b: bool) usize {...@@ -190,16 +190,16 @@ fn testTryToTrickEvalWithRuntimeIf(b: bool) usize {
190 }190 }
191}191}
192192
193//test "inlined loop has array literal with elided runtime scope on first iteration but not second iteration" {193test "inlined loop has array literal with elided runtime scope on first iteration but not second iteration" {
194// var runtime = [1]i32{3};194 var runtime = [1]i32{3};
195// comptime var i: usize = 0;195 comptime var i: usize = 0;
196// inline while (i < 2) : (i += 1) {196 inline while (i < 2) : (i += 1) {
197// const result = if (i == 0) [1]i32{2} else runtime;197 const result = if (i == 0) [1]i32{2} else runtime;
198// }198 }
199// comptime {199 comptime {
200// expect(i == 2);200 expect(i == 2);
201// }201 }
202//}202}
203203
204fn max(comptime T: type, a: T, b: T) T {204fn max(comptime T: type, a: T, b: T) T {
205 if (T == bool) {205 if (T == bool) {
...@@ -668,9 +668,9 @@ fn loopNTimes(comptime n: usize) void {...@@ -668,9 +668,9 @@ fn loopNTimes(comptime n: usize) void {
668 inline while (i < n) : (i += 1) {}668 inline while (i < n) : (i += 1) {}
669}669}
670670
671//test "variable inside inline loop that has different types on different iterations" {671test "variable inside inline loop that has different types on different iterations" {
672// testVarInsideInlineLoop(true, u32(42));672 testVarInsideInlineLoop(true, u32(42));
673//}673}
674674
675fn testVarInsideInlineLoop(args: ...) void {675fn testVarInsideInlineLoop(args: ...) void {
676 comptime var i = 0;676 comptime var i = 0;
...@@ -681,14 +681,14 @@ fn testVarInsideInlineLoop(args: ...) void {...@@ -681,14 +681,14 @@ fn testVarInsideInlineLoop(args: ...) void {
681 }681 }
682}682}
683683
684//test "inline for with same type but different values" {684test "inline for with same type but different values" {
685// var res: usize = 0;685 var res: usize = 0;
686// inline for ([_]type{ [2]u8, [1]u8, [2]u8 }) |T| {686 inline for ([_]type{ [2]u8, [1]u8, [2]u8 }) |T| {
687// var a: T = undefined;687 var a: T = undefined;
688// res += a.len;688 res += a.len;
689// }689 }
690// expect(res == 5);690 expect(res == 5);
691//}691}
692692
693test "refer to the type of a generic function" {693test "refer to the type of a generic function" {
694 const Func = fn (type) void;694 const Func = fn (type) void;