| ... | ... | @@ -322,3 +322,33 @@ test "nested packed structs" { |
| 322 | 322 | try expectEqual(9, @offsetOf(S6, "c")); |
| 323 | 323 | try expectEqual(72, @bitOffsetOf(S6, "c")); |
| 324 | 324 | } |
| 325 | |
| 326 | test "regular in irregular packed struct" { |
| 327 | if (builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; |
| 328 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| 329 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 330 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 331 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 332 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 333 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; |
| 334 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; |
| 335 | |
| 336 | const Irregular = packed struct { |
| 337 | bar: Regular = Regular{}, |
| 338 | |
| 339 | // This field forces the regular packed struct to be a part of single u48 |
| 340 | // and thus it all gets represented as an array of 6 bytes in LLVM |
| 341 | _: u24 = 0, |
| 342 | |
| 343 | // This struct on its own can represent its fields directly in LLVM |
| 344 | // with no need to use array of bytes as underlaying representation. |
| 345 | pub const Regular = packed struct { a: u16 = 0, b: u8 = 0 }; |
| 346 | }; |
| 347 | |
| 348 | var foo = Irregular{}; |
| 349 | foo.bar.a = 235; |
| 350 | foo.bar.b = 42; |
| 351 | |
| 352 | try expectEqual(@as(u16, 235), foo.bar.a); |
| 353 | try expectEqual(@as(u8, 42), foo.bar.b); |
| 354 | } |