diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-06-18 17:43:05 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-06-18 17:43:05 -0400 |
| commit | 79671efd3a5b67e359aa60c66e4007c03342b28e (patch) | |
| tree | 410d812c520924418e326497e5343dd431a37d01 | |
| parent | e27da17ff2cc45c93ab95defd937fd8038751b51 (diff) | |
| download | zig-79671efd3a5b67e359aa60c66e4007c03342b28e.tar.gz zig-79671efd3a5b67e359aa60c66e4007c03342b28e.zip | |
fix inline loop behavior with variable result loc
| -rw-r--r-- | src/ir.cpp | 7 | ||||
| -rw-r--r-- | test/stage1/behavior/eval.zig | 42 |
2 files changed, 27 insertions, 22 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 4d2221ab39..83199fc0cc 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -15157,9 +15157,14 @@ static void ir_reset_result(ResultLoc *result_loc) { } break; } + case ResultLocIdVar: { + IrInstructionAllocaSrc *alloca_src = + reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction); + alloca_src->base.child = nullptr; + break; + } case ResultLocIdPeer: case ResultLocIdNone: - case ResultLocIdVar: case ResultLocIdReturn: case ResultLocIdInstruction: case ResultLocIdBitCast: diff --git a/test/stage1/behavior/eval.zig b/test/stage1/behavior/eval.zig index 49c7380f2b..62cedbc76f 100644 --- a/test/stage1/behavior/eval.zig +++ b/test/stage1/behavior/eval.zig @@ -190,16 +190,16 @@ fn testTryToTrickEvalWithRuntimeIf(b: bool) usize { } } -//test "inlined loop has array literal with elided runtime scope on first iteration but not second iteration" { -// var runtime = [1]i32{3}; -// comptime var i: usize = 0; -// inline while (i < 2) : (i += 1) { -// const result = if (i == 0) [1]i32{2} else runtime; -// } -// comptime { -// expect(i == 2); -// } -//} +test "inlined loop has array literal with elided runtime scope on first iteration but not second iteration" { + var runtime = [1]i32{3}; + comptime var i: usize = 0; + inline while (i < 2) : (i += 1) { + const result = if (i == 0) [1]i32{2} else runtime; + } + comptime { + expect(i == 2); + } +} fn max(comptime T: type, a: T, b: T) T { if (T == bool) { @@ -668,9 +668,9 @@ fn loopNTimes(comptime n: usize) void { inline while (i < n) : (i += 1) {} } -//test "variable inside inline loop that has different types on different iterations" { -// testVarInsideInlineLoop(true, u32(42)); -//} +test "variable inside inline loop that has different types on different iterations" { + testVarInsideInlineLoop(true, u32(42)); +} fn testVarInsideInlineLoop(args: ...) void { comptime var i = 0; @@ -681,14 +681,14 @@ fn testVarInsideInlineLoop(args: ...) void { } } -//test "inline for with same type but different values" { -// var res: usize = 0; -// inline for ([_]type{ [2]u8, [1]u8, [2]u8 }) |T| { -// var a: T = undefined; -// res += a.len; -// } -// expect(res == 5); -//} +test "inline for with same type but different values" { + var res: usize = 0; + inline for ([_]type{ [2]u8, [1]u8, [2]u8 }) |T| { + var a: T = undefined; + res += a.len; + } + expect(res == 5); +} test "refer to the type of a generic function" { const Func = fn (type) void; |
