aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-09-07 17:37:17 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-09-07 17:37:17 -0400
commit229323e13a074e94ef8a58409c81cfd9ac807dd8 (patch)
tree07e39a8d4656fcd930b381466d07e67bb8bb837b /test
parentd3cf040c900c14feec427f3835f247b6a4c616bb (diff)
downloadzig-229323e13a074e94ef8a58409c81cfd9ac807dd8.tar.gz
zig-229323e13a074e94ef8a58409c81cfd9ac807dd8.zip
fix suspensions inside for loops generating invalid LLVM IR
closes #3076
Diffstat (limited to 'test')
-rw-r--r--test/stage1/behavior/async_fn.zig27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/stage1/behavior/async_fn.zig b/test/stage1/behavior/async_fn.zig
index f5669f0fca..b8a7196ed6 100644
--- a/test/stage1/behavior/async_fn.zig
+++ b/test/stage1/behavior/async_fn.zig
@@ -1151,3 +1151,30 @@ test "async fn call used in expression after a fn call" {
};
_ = async S.atest();
}
+
+test "suspend in for loop" {
+ const S = struct {
+ var global_frame: ?anyframe = null;
+
+ fn doTheTest() void {
+ _ = async atest();
+ while (global_frame) |f| resume f;
+ }
+
+ fn atest() void {
+ expect(func([_]u8{ 1, 2, 3 }) == 6);
+ }
+ fn func(stuff: []const u8) u32 {
+ global_frame = @frame();
+ var sum: u32 = 0;
+ for (stuff) |x| {
+ suspend;
+ sum += x;
+ }
+ global_frame = null;
+ return sum;
+ }
+ };
+ S.doTheTest();
+}
+