authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-02 14:59:31-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-02 22:06:02-07:00
logd98869da430b0ab7054600dd0cb80a6d45ce0639
tree49a1cfba9e30ba4052ccb5d6585ed4d76ed676f3
parent1a1f62a0ce0565a7f6da9b4b8654407f6c514cb0

behavior tests: fix wrong packed struct test case

Packed structs are defined to have the same alignment and size as their backing integer.

1 files changed, 4 insertions(+), 15 deletions(-)

test/behavior/struct.zig+4-15
...@@ -421,21 +421,10 @@ test "packed struct 24bits" {...@@ -421,21 +421,10 @@ test "packed struct 24bits" {
421 if (builtin.cpu.arch == .arm) return error.SkipZigTest; // TODO421 if (builtin.cpu.arch == .arm) return error.SkipZigTest; // TODO
422422
423 comptime {423 comptime {
424 // TODO Remove if and leave only the else branch when it is also fixed in stage2424 // stage1 gets the wrong answer for sizeof
425 if (builtin.zig_backend == .stage2_llvm or builtin.zig_backend == .stage2_x86 or425 if (builtin.zig_backend != .stage1) {
426 builtin.zig_backend == .stage2_riscv64)426 std.debug.assert(@sizeOf(Foo24Bits) == @sizeOf(u24));
427 {427 std.debug.assert(@sizeOf(Foo96Bits) == @sizeOf(u96));
428 // Stage 2 still expects the wrong values
429 try expect(@sizeOf(Foo24Bits) == 4);
430 if (@sizeOf(usize) == 4) {
431 try expect(@sizeOf(Foo96Bits) == 12);
432 } else {
433 try expect(@sizeOf(Foo96Bits) == 16);
434 }
435 } else {
436 // Stage1 is now fixed and is expected to return right values
437 try expectEqual(@sizeOf(Foo24Bits), 3);
438 try expectEqual(@sizeOf(Foo96Bits), 12);
439 }428 }
440 }429 }
441430