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 @@ -10096,7 +10096,7 @@ fn llvmFieldIndex(
10096
10096
llvm_field_index += 1 ;
10097
10097
}
10098
10098
10099
- if (field_index = = i ) {
10099
+ if (field_index < = i ) {
10100
10100
ptr_pl_buf .* = .{
10101
10101
.data = .{
10102
10102
.pointee_type = field_ty ,
@@ -10129,7 +10129,7 @@ fn llvmFieldIndex(
10129
10129
llvm_field_index += 1 ;
10130
10130
}
10131
10131
10132
- if (field_index = = i ) {
10132
+ if (field_index < = i ) {
10133
10133
ptr_pl_buf .* = .{
10134
10134
.data = .{
10135
10135
.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