aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/struct.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-12-18 06:50:48 -0500
committerGitHub <noreply@github.com>2022-12-18 06:50:48 -0500
commitf24c77fc48b7272618b48cac7bb15d6997e95c5a (patch)
treecc75a53ed2774ae1556f0f0d5a16c2b60b9eb32a /test/behavior/struct.zig
parent4809e0ea7f53d1b56cbc4c6e62e4b8ea40936d44 (diff)
parente0bc5f65b98d154b4318027d56f780b55605e33c (diff)
downloadzig-f24c77fc48b7272618b48cac7bb15d6997e95c5a.tar.gz
zig-f24c77fc48b7272618b48cac7bb15d6997e95c5a.zip
Merge pull request #13992 from jacobly0/llvm-zwf
llvm: fix null pointer use when lowering pointer to final zero-width field of a comptime value
Diffstat (limited to 'test/behavior/struct.zig')
-rw-r--r--test/behavior/struct.zig36
1 files changed, 23 insertions, 13 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig
index db7092ab82..0984f7d1e4 100644
--- a/test/behavior/struct.zig
+++ b/test/behavior/struct.zig
@@ -1359,23 +1359,33 @@ test "under-aligned struct field" {
try expect(result == 1234);
}
-test "address of zero-bit field is equal to address of only field" {
+test "fieldParentPtr of a zero-bit field" {
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- {
- const A = struct { b: void = {}, u: u8 };
- var a = A{ .u = 0 };
- const a_ptr = @fieldParentPtr(A, "b", &a.b);
- try std.testing.expectEqual(&a, a_ptr);
- }
- {
- const A = struct { u: u8, b: void = {} };
- var a = A{ .u = 0 };
- const a_ptr = @fieldParentPtr(A, "b", &a.b);
- try std.testing.expectEqual(&a, a_ptr);
- }
+ const S = struct {
+ fn testOneType(comptime A: type) !void {
+ {
+ const a = A{ .u = 0 };
+ const b_ptr = &a.b;
+ const a_ptr = @fieldParentPtr(A, "b", b_ptr);
+ try std.testing.expectEqual(&a, a_ptr);
+ }
+ {
+ var a = A{ .u = 0 };
+ const b_ptr = &a.b;
+ const a_ptr = @fieldParentPtr(A, "b", b_ptr);
+ try std.testing.expectEqual(&a, a_ptr);
+ }
+ }
+ fn doTheTest() !void {
+ try testOneType(struct { b: void = {}, u: u8 });
+ try testOneType(struct { u: u8, b: void = {} });
+ }
+ };
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "struct field has a pointer to an aligned version of itself" {