behavior tests: fix wrong packed struct test case

Packed structs are defined to have the same alignment and size as their
backing integer.
This commit is contained in:
Andrew Kelley 2022-05-02 14:59:31 -07:00
parent 1a1f62a0ce
commit d98869da43

View File

@ -421,21 +421,10 @@ test "packed struct 24bits" {
if (builtin.cpu.arch == .arm) return error.SkipZigTest; // TODO if (builtin.cpu.arch == .arm) return error.SkipZigTest; // TODO
comptime { comptime {
// TODO Remove if and leave only the else branch when it is also fixed in stage2 // stage1 gets the wrong answer for sizeof
if (builtin.zig_backend == .stage2_llvm or builtin.zig_backend == .stage2_x86 or if (builtin.zig_backend != .stage1) {
builtin.zig_backend == .stage2_riscv64) std.debug.assert(@sizeOf(Foo24Bits) == @sizeOf(u24));
{ std.debug.assert(@sizeOf(Foo96Bits) == @sizeOf(u96));
// Stage 2 still expects the wrong values
try expect(@sizeOf(Foo24Bits) == 4);
if (@sizeOf(usize) == 4) {
try expect(@sizeOf(Foo96Bits) == 12);
} else {
try expect(@sizeOf(Foo96Bits) == 16);
}
} else {
// Stage1 is now fixed and is expected to return right values
try expectEqual(@sizeOf(Foo24Bits), 3);
try expectEqual(@sizeOf(Foo96Bits), 12);
} }
} }