File tree 2 files changed +22
-2
lines changed
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -10216,7 +10216,7 @@ fn llvmFieldIndex(
10216
10216
llvm_field_index += 1 ;
10217
10217
}
10218
10218
10219
- if (field_index = = i ) {
10219
+ if (field_index < = i ) {
10220
10220
ptr_pl_buf .* = .{
10221
10221
.data = .{
10222
10222
.pointee_type = field_ty ,
@@ -10249,7 +10249,7 @@ fn llvmFieldIndex(
10249
10249
llvm_field_index += 1 ;
10250
10250
}
10251
10251
10252
- if (field_index = = i ) {
10252
+ if (field_index < = i ) {
10253
10253
ptr_pl_buf .* = .{
10254
10254
.data = .{
10255
10255
.pointee_type = field .ty ,
Original file line number Diff line number Diff line change @@ -1398,3 +1398,23 @@ test "under-aligned struct field" {
1398
1398
const result = std .mem .readIntNative (u64 , array [4.. 12]);
1399
1399
try expect (result == 1234 );
1400
1400
}
1401
+
1402
+ test "address of zero-bit field is equal to address of only field" {
1403
+ if (builtin .zig_backend == .stage2_x86_64 ) return error .SkipZigTest ; // TODO
1404
+ if (builtin .zig_backend == .stage2_aarch64 ) return error .SkipZigTest ; // TODO
1405
+ if (builtin .zig_backend == .stage2_arm ) return error .SkipZigTest ; // TODO
1406
+ if (builtin .zig_backend == .stage2_c ) return error .SkipZigTest ; // TODO
1407
+
1408
+ {
1409
+ const A = struct { b : void = {}, u : u8 };
1410
+ var a = A { .u = 0 };
1411
+ const a_ptr = @fieldParentPtr (A , "b" , & a .b );
1412
+ try std .testing .expectEqual (& a , a_ptr );
1413
+ }
1414
+ {
1415
+ const A = struct { u : u8 , b : void = {} };
1416
+ var a = A { .u = 0 };
1417
+ const a_ptr = @fieldParentPtr (A , "b" , & a .b );
1418
+ try std .testing .expectEqual (& a , a_ptr );
1419
+ }
1420
+ }
You can’t perform that action at this time.
0 commit comments