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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user