diff options
| author | Cody Tapscott <topolarity@tapscott.me> | 2022-03-15 14:00:33 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-03-15 17:01:16 -0700 |
| commit | 480e7eec65c02952b71ecc2f4ff2adccb6092a5f (patch) | |
| tree | b3637be2086b25649d71e2d24d334aa634e87e03 /test/behavior | |
| parent | 762c4a876bfa999d5f49edc7bbaf2917c06d320d (diff) | |
| download | zig-480e7eec65c02952b71ecc2f4ff2adccb6092a5f.tar.gz zig-480e7eec65c02952b71ecc2f4ff2adccb6092a5f.zip | |
stage2: Fix panic on initializing comptime fields in tuple
This resolves https://github.com/ziglang/zig/issues/11159
The problem was that:
1. We were not correctly deleting the field stores after recognizing
that an array initializer was a comptime-known value.
2. LLVM was not checking that the final type had no runtime bits, and
so would generate an invalid store.
This also adds several test cases for related bugs, just to check these
in for later work.
Diffstat (limited to 'test/behavior')
| -rw-r--r-- | test/behavior/bugs/11159.zig | 23 | ||||
| -rw-r--r-- | test/behavior/bugs/11162.zig | 16 | ||||
| -rw-r--r-- | test/behavior/bugs/11182.zig | 10 |
3 files changed, 49 insertions, 0 deletions
diff --git a/test/behavior/bugs/11159.zig b/test/behavior/bugs/11159.zig new file mode 100644 index 0000000000..fdd3807059 --- /dev/null +++ b/test/behavior/bugs/11159.zig @@ -0,0 +1,23 @@ +const std = @import("std"); +const builtin = @import("builtin"); + +test { + const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) }); + var a: T = .{ 0, 0 }; + _ = a; +} + +test { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO + + const S = struct { + comptime x: i32 = 0, + comptime y: u32 = 0, + }; + var a: S = .{}; + _ = a; + var b = S{}; + _ = b; +} diff --git a/test/behavior/bugs/11162.zig b/test/behavior/bugs/11162.zig new file mode 100644 index 0000000000..ced435a305 --- /dev/null +++ b/test/behavior/bugs/11162.zig @@ -0,0 +1,16 @@ +const std = @import("std"); +const builtin = @import("builtin"); +const expect = std.testing.expect; + +test { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; // TODO + if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO + + var x: u32 = 15; + const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); + var a: T = .{ -1234, 5678, x + 1 }; + + try expect(a[0] == -1234); + try expect(a[1] == 5678); + try expect(a[2] == 16); +} diff --git a/test/behavior/bugs/11182.zig b/test/behavior/bugs/11182.zig new file mode 100644 index 0000000000..eb4ee8ac9d --- /dev/null +++ b/test/behavior/bugs/11182.zig @@ -0,0 +1,10 @@ +const std = @import("std"); +const builtin = @import("builtin"); + +test { + if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO + + const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) }); + var a = T{ 0, 0 }; + _ = a; +} |
