aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/struct.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-11-08 19:31:09 +0200
committerVeikka Tuominen <git@vexu.eu>2022-11-11 17:59:53 +0200
commitd2cc55109a64aaf004384b942e08e95829b9341f (patch)
treea58057825963288dc93d51c6295b5879611d8493 /test/behavior/struct.zig
parentc4465556fdf14d87f718a7aced5210ec457c1f5a (diff)
downloadzig-d2cc55109a64aaf004384b942e08e95829b9341f.tar.gz
zig-d2cc55109a64aaf004384b942e08e95829b9341f.zip
llvm: correct calculation of index of zero-bit field
If the field comes before any non-zero-bit field then the index of the next field should be returned. Closes #13363
Diffstat (limited to 'test/behavior/struct.zig')
-rw-r--r--test/behavior/struct.zig20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig
index a6cfd0f987..b598dca026 100644
--- a/test/behavior/struct.zig
+++ b/test/behavior/struct.zig
@@ -1398,3 +1398,23 @@ test "under-aligned struct field" {
const result = std.mem.readIntNative(u64, array[4..12]);
try expect(result == 1234);
}
+
+test "address of zero-bit field is equal to address of only 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
+ if (builtin.zig_backend == .stage2_c) 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);
+ }
+}