authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-26 15:35:46-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-26 16:53:23-07:00
logd62229e3ad6069597b74874ba3b84fc185b2fa4c
treef2618b8263edb55fd0fd4c6cebaa9890b4b5838d
parent822d29286bd39b7331970e1e641ad240e7b62aee

Sema: Module.Union.abiAlignment can return 0

When the union is a 0-bit type.

3 files changed, 20 insertions(+), 20 deletions(-)

src/Module.zig+1-1
......@@ -1210,6 +1210,7 @@ pub const Union = struct {
12101210 return @intCast(u32, most_index);
12111211 }
12121212
1213 /// Returns 0 if the union is represented with 0 bits at runtime.
12131214 pub fn abiAlignment(u: Union, target: Target, have_tag: bool) u32 {
12141215 var max_align: u32 = 0;
12151216 if (have_tag) max_align = u.tag_ty.abiAlignment(target);
......@@ -1225,7 +1226,6 @@ pub const Union = struct {
12251226 };
12261227 max_align = @maximum(max_align, field_align);
12271228 }
1228 assert(max_align != 0);
12291229 return max_align;
12301230 }
12311231
test/behavior/floatop.zig+16-18
......@@ -155,15 +155,14 @@ test "@sin" {
155155
156156fn testSin() !void {
157157 // stage1 emits an incorrect compile error for `@as(ty, std.math.pi / 2)`
158 // so skip the rest of the tests.
159 if (builtin.zig_backend != .stage1) {
160 inline for ([_]type{ f16, f32, f64 }) |ty| {
161 const eps = epsForType(ty);
162 try expect(@sin(@as(ty, 0)) == 0);
163 try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi)), 0, eps));
164 try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi / 2)), 1, eps));
165 try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi / 4)), 0.7071067811865475, eps));
166 }
158 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
159
160 inline for ([_]type{ f16, f32, f64 }) |ty| {
161 const eps = epsForType(ty);
162 try expect(@sin(@as(ty, 0)) == 0);
163 try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi)), 0, eps));
164 try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi / 2)), 1, eps));
165 try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi / 4)), 0.7071067811865475, eps));
167166 }
168167
169168 {
......@@ -183,15 +182,14 @@ test "@cos" {
183182
184183fn testCos() !void {
185184 // stage1 emits an incorrect compile error for `@as(ty, std.math.pi / 2)`
186 // so skip the rest of the tests.
187 if (builtin.zig_backend != .stage1) {
188 inline for ([_]type{ f16, f32, f64 }) |ty| {
189 const eps = epsForType(ty);
190 try expect(@cos(@as(ty, 0)) == 1);
191 try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi)), -1, eps));
192 try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi / 2)), 0, eps));
193 try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi / 4)), 0.7071067811865475, eps));
194 }
185 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
186
187 inline for ([_]type{ f16, f32, f64 }) |ty| {
188 const eps = epsForType(ty);
189 try expect(@cos(@as(ty, 0)) == 1);
190 try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi)), -1, eps));
191 try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi / 2)), 0, eps));
192 try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi / 4)), 0.7071067811865475, eps));
195193 }
196194
197195 {
test/behavior/union.zig+3-1
......@@ -648,7 +648,9 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) !void {
648648}
649649
650650test "switch on union with only 1 field" {
651 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
651 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
652 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
653 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
652654
653655 var r: PartialInst = undefined;
654656 r = PartialInst.Compiled;