diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-10-22 23:43:27 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-10-22 23:43:27 -0400 |
| commit | e98e5dda52d8bcaa2e59861bbbd500b81edfde2d (patch) | |
| tree | 50446ef28111840f0fe92b5a7ea2851af9fb08c0 /test | |
| parent | 1dcf540426103e762925f3365898d65b1724fdf1 (diff) | |
| download | zig-e98e5dda52d8bcaa2e59861bbbd500b81edfde2d.tar.gz zig-e98e5dda52d8bcaa2e59861bbbd500b81edfde2d.zip | |
implement safety for resuming non-suspended function
closes #3469
Diffstat (limited to 'test')
| -rw-r--r-- | test/runtime_safety.zig | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/runtime_safety.zig b/test/runtime_safety.zig index 17f0f3230c..d278407ee1 100644 --- a/test/runtime_safety.zig +++ b/test/runtime_safety.zig @@ -1,6 +1,54 @@ const tests = @import("tests.zig"); pub fn addCases(cases: *tests.CompareOutputContext) void { + cases.addRuntimeSafety("resuming a non-suspended function which never been suspended", + \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn { + \\ @import("std").os.exit(126); + \\} + \\fn foo() void { + \\ var f = async bar(@frame()); + \\ @import("std").os.exit(0); + \\} + \\ + \\fn bar(frame: anyframe) void { + \\ suspend { + \\ resume frame; + \\ } + \\ @import("std").os.exit(0); + \\} + \\ + \\pub fn main() void { + \\ _ = async foo(); + \\} + ); + + cases.addRuntimeSafety("resuming a non-suspended function which has been suspended and resumed", + \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn { + \\ @import("std").os.exit(126); + \\} + \\fn foo() void { + \\ suspend { + \\ global_frame = @frame(); + \\ } + \\ var f = async bar(@frame()); + \\ @import("std").os.exit(0); + \\} + \\ + \\fn bar(frame: anyframe) void { + \\ suspend { + \\ resume frame; + \\ } + \\ @import("std").os.exit(0); + \\} + \\ + \\var global_frame: anyframe = undefined; + \\pub fn main() void { + \\ _ = async foo(); + \\ resume global_frame; + \\ @import("std").os.exit(0); + \\} + ); + cases.addRuntimeSafety("noasync function call, callee suspends", \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn { \\ @import("std").os.exit(126); |
