From d62229e3ad6069597b74874ba3b84fc185b2fa4c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 26 Feb 2022 15:35:46 -0700 Subject: [PATCH] Sema: Module.Union.abiAlignment can return 0 When the union is a 0-bit type. --- src/Module.zig | 2 +- test/behavior/floatop.zig | 34 ++++++++++++++++------------------ test/behavior/union.zig | 4 +++- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Module.zig b/src/Module.zig index 7f52dc23e94b27566f65c49ed1a885a9895940df..91386405be0564b3fe4e3761ea177b76fd1e5618 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -1210,6 +1210,7 @@ pub const Union = struct { return @intCast(u32, most_index); } + /// Returns 0 if the union is represented with 0 bits at runtime. pub fn abiAlignment(u: Union, target: Target, have_tag: bool) u32 { var max_align: u32 = 0; if (have_tag) max_align = u.tag_ty.abiAlignment(target); @@ -1225,7 +1226,6 @@ pub const Union = struct { }; max_align = @maximum(max_align, field_align); } - assert(max_align != 0); return max_align; } diff --git a/test/behavior/floatop.zig b/test/behavior/floatop.zig index 85d5cec1e6d48d84c28ab9d322e30bce801baf78..5597be122e588522ddbb4f57dc7608e37361beeb 100644 --- a/test/behavior/floatop.zig +++ b/test/behavior/floatop.zig @@ -155,15 +155,14 @@ test "@sin" { fn testSin() !void { // stage1 emits an incorrect compile error for `@as(ty, std.math.pi / 2)` - // so skip the rest of the tests. - if (builtin.zig_backend != .stage1) { - inline for ([_]type{ f16, f32, f64 }) |ty| { - const eps = epsForType(ty); - try expect(@sin(@as(ty, 0)) == 0); - try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi)), 0, eps)); - try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi / 2)), 1, eps)); - try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi / 4)), 0.7071067811865475, eps)); - } + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + + inline for ([_]type{ f16, f32, f64 }) |ty| { + const eps = epsForType(ty); + try expect(@sin(@as(ty, 0)) == 0); + try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi)), 0, eps)); + try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi / 2)), 1, eps)); + try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi / 4)), 0.7071067811865475, eps)); } { @@ -183,15 +182,14 @@ test "@cos" { fn testCos() !void { // stage1 emits an incorrect compile error for `@as(ty, std.math.pi / 2)` - // so skip the rest of the tests. - if (builtin.zig_backend != .stage1) { - inline for ([_]type{ f16, f32, f64 }) |ty| { - const eps = epsForType(ty); - try expect(@cos(@as(ty, 0)) == 1); - try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi)), -1, eps)); - try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi / 2)), 0, eps)); - try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi / 4)), 0.7071067811865475, eps)); - } + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + + inline for ([_]type{ f16, f32, f64 }) |ty| { + const eps = epsForType(ty); + try expect(@cos(@as(ty, 0)) == 1); + try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi)), -1, eps)); + try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi / 2)), 0, eps)); + try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi / 4)), 0.7071067811865475, eps)); } { diff --git a/test/behavior/union.zig b/test/behavior/union.zig index 7f78ca9adf51a25d06ab2545171386edc824c84b..a3549e9599954fdb02ef509999fe00e38e8acf7b 100644 --- a/test/behavior/union.zig +++ b/test/behavior/union.zig @@ -648,7 +648,9 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) !void { } test "switch on union with only 1 field" { - if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO var r: PartialInst = undefined; r = PartialInst.Compiled; -- 2.54.0