diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-08-02 18:32:44 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-02 18:32:44 +0300 |
| commit | 4831c1c65f51ccfdb48c8d16bdf77435e0256070 (patch) | |
| tree | 62ed249f1b2ce780c511b7aa6304104c4cd5bc90 /test/behavior | |
| parent | 2375658da9f8e73d3e4b6d14d88c02cc765ae579 (diff) | |
| parent | e47706f34454c46dd00fe10fdf9252657117a00d (diff) | |
| download | zig-4831c1c65f51ccfdb48c8d16bdf77435e0256070.tar.gz zig-4831c1c65f51ccfdb48c8d16bdf77435e0256070.zip | |
Merge pull request #12277 from Vexu/stage2-compile-errors
Stage2: validate packed struct field types
Diffstat (limited to 'test/behavior')
| -rw-r--r-- | test/behavior/bitcast.zig | 16 | ||||
| -rw-r--r-- | test/behavior/packed-struct.zig | 28 | ||||
| -rw-r--r-- | test/behavior/sizeof_and_typeof.zig | 2 | ||||
| -rw-r--r-- | test/behavior/struct.zig | 6 |
4 files changed, 6 insertions, 46 deletions
diff --git a/test/behavior/bitcast.zig b/test/behavior/bitcast.zig index b0c66fd92b..27a0692a44 100644 --- a/test/behavior/bitcast.zig +++ b/test/behavior/bitcast.zig @@ -90,22 +90,6 @@ test "nested bitcast" { comptime try S.foo(42); } -test "@bitCast enum to its integer type" { - const SOCK = enum(c_int) { - A, - B, - - fn testBitCastExternEnum() !void { - var SOCK_DGRAM = @This().B; - var sock_dgram = @bitCast(c_int, SOCK_DGRAM); - try expect(sock_dgram == 1); - } - }; - - try SOCK.testBitCastExternEnum(); - comptime try SOCK.testBitCastExternEnum(); -} - // issue #3010: compiler segfault test "bitcast literal [4]u8 param to u32" { const ip = @bitCast(u32, [_]u8{ 255, 255, 255, 255 }); diff --git a/test/behavior/packed-struct.zig b/test/behavior/packed-struct.zig index 2dea485bf5..8c34f5741b 100644 --- a/test/behavior/packed-struct.zig +++ b/test/behavior/packed-struct.zig @@ -6,6 +6,8 @@ const expectEqual = std.testing.expectEqual; const native_endian = builtin.cpu.arch.endian(); test "correct size of packed structs" { + // Stage2 has different packed struct semantics. + if (builtin.zig_backend != .stage1) return error.SkipZigTest; const T1 = packed struct { one: u8, three: [3]u8 }; try expectEqual(4, @sizeOf(T1)); @@ -118,18 +120,6 @@ test "flags in packed structs" { try expectEqual(32, @bitSizeOf(Flags3)); } -test "arrays in packed structs" { - if (builtin.zig_backend == .stage1) return error.SkipZigTest; - - const T1 = packed struct { array: [3][3]u8 }; - const T2 = packed struct { array: [9]u8 }; - - try expectEqual(@sizeOf(u72), @sizeOf(T1)); - try expectEqual(72, @bitSizeOf(T1)); - try expectEqual(@sizeOf(u72), @sizeOf(T2)); - try expectEqual(72, @bitSizeOf(T2)); -} - test "consistent size of packed structs" { if (builtin.zig_backend == .stage1) return error.SkipZigTest; @@ -145,23 +135,15 @@ test "consistent size of packed structs" { try expectEqual(register_size_bits, @bitSizeOf(TxData2)); try expectEqual(register_size_bytes, @sizeOf(TxData2)); - const TxData3 = packed struct { a: u32, b: [3]u8 }; const TxData4 = packed struct { a: u32, b: u24 }; - const TxData5 = packed struct { a: [3]u8, b: u32 }; const TxData6 = packed struct { a: u24, b: u32 }; const expectedBitSize = 56; const expectedByteSize = @sizeOf(u56); - try expectEqual(expectedBitSize, @bitSizeOf(TxData3)); - try expectEqual(expectedByteSize, @sizeOf(TxData3)); - try expectEqual(expectedBitSize, @bitSizeOf(TxData4)); try expectEqual(expectedByteSize, @sizeOf(TxData4)); - try expectEqual(expectedBitSize, @bitSizeOf(TxData5)); - try expectEqual(expectedByteSize, @sizeOf(TxData5)); - try expectEqual(expectedBitSize, @bitSizeOf(TxData6)); try expectEqual(expectedByteSize, @sizeOf(TxData6)); } @@ -234,12 +216,6 @@ test "correct sizeOf and offsets in packed structs" { try expectEqual(@as(u7, 0b1111010), s2.y); try expectEqual(@as(u24, 0xd5c71f), s2.z); } - - const S = packed struct { a: u32, pad: [3]u32, b: u32 }; - - try expectEqual(16, @offsetOf(S, "b")); - try expectEqual(128, @bitOffsetOf(S, "b")); - try expectEqual(@sizeOf(u160), @sizeOf(S)); } test "nested packed structs" { diff --git a/test/behavior/sizeof_and_typeof.zig b/test/behavior/sizeof_and_typeof.zig index 6c7e16b502..83c5d977be 100644 --- a/test/behavior/sizeof_and_typeof.zig +++ b/test/behavior/sizeof_and_typeof.zig @@ -105,6 +105,8 @@ test "@offsetOf" { } test "@offsetOf packed struct, array length not power of 2 or multiple of native pointer width in bytes" { + // Stage2 has different packed struct semantics. + if (builtin.zig_backend != .stage1) return error.SkipZigTest; const p3a_len = 3; const P3 = packed struct { a: [p3a_len]u8, diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 8fac5697ec..377cbb56f4 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -704,10 +704,8 @@ const FooArray24Bits = packed struct { }; test "aligned array of packed struct" { - if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO - if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO - if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO - if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + // Stage2 has different packed struct semantics. + if (builtin.zig_backend != .stage1) return error.SkipZigTest; comptime { try expect(@sizeOf(FooStructAligned) == 2); |
