authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-17 19:23:08-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-06-17 19:23:08-04:00
log33cf6ef621114daad63d14067b6ff374e664d410
tree9828aa24009a7f03a446433606c46e14f5667587
parentb66247c97af3deaa190d1ca8297166f932b022ff
parent28986a059075c2dce662c2f4e823b3efd283df87
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #11881 from Vexu/stage2

Stage2: fixes for bugs found while looking for miscompilations

5 files changed, 48 insertions(+), 12 deletions(-)

lib/std/bit_set.zig-4
......@@ -1330,7 +1330,6 @@ fn testStaticBitSet(comptime Set: type) !void {
13301330}
13311331
13321332test "IntegerBitSet" {
1333 if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
13341333 try testStaticBitSet(IntegerBitSet(0));
13351334 try testStaticBitSet(IntegerBitSet(1));
13361335 try testStaticBitSet(IntegerBitSet(2));
......@@ -1342,7 +1341,6 @@ test "IntegerBitSet" {
13421341}
13431342
13441343test "ArrayBitSet" {
1345 if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
13461344 if (@import("builtin").cpu.arch == .aarch64) {
13471345 // https://github.com/ziglang/zig/issues/9879
13481346 return error.SkipZigTest;
......@@ -1357,7 +1355,6 @@ test "ArrayBitSet" {
13571355}
13581356
13591357test "DynamicBitSetUnmanaged" {
1360 if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
13611358 const allocator = std.testing.allocator;
13621359 var a = try DynamicBitSetUnmanaged.initEmpty(allocator, 300);
13631360 try testing.expectEqual(@as(usize, 0), a.count());
......@@ -1398,7 +1395,6 @@ test "DynamicBitSetUnmanaged" {
13981395}
13991396
14001397test "DynamicBitSet" {
1401 if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
14021398 const allocator = std.testing.allocator;
14031399 var a = try DynamicBitSet.initEmpty(allocator, 300);
14041400 try testing.expectEqual(@as(usize, 0), a.count());
lib/std/tz.zig+1-4
......@@ -11,7 +11,7 @@ pub const Timetype = struct {
1111 flags: u8,
1212 name_data: [6:0]u8,
1313
14 pub fn name(self: Timetype) [:0]const u8 {
14 pub fn name(self: *const Timetype) [:0]const u8 {
1515 return std.mem.sliceTo(self.name_data[0..], 0);
1616 }
1717
......@@ -214,7 +214,6 @@ pub const Tz = struct {
214214};
215215
216216test "slim" {
217 if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
218217 const data = @embedFile("tz/asia_tokyo.tzif");
219218 var in_stream = std.io.fixedBufferStream(data);
220219
......@@ -228,7 +227,6 @@ test "slim" {
228227}
229228
230229test "fat" {
231 if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
232230 const data = @embedFile("tz/antarctica_davis.tzif");
233231 var in_stream = std.io.fixedBufferStream(data);
234232
......@@ -241,7 +239,6 @@ test "fat" {
241239}
242240
243241test "legacy" {
244 if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
245242 // Taken from Slackware 8.0, from 2001
246243 const data = @embedFile("tz/europe_vatican.tzif");
247244 var in_stream = std.io.fixedBufferStream(data);
src/Sema.zig+35-3
......@@ -3795,6 +3795,32 @@ fn zirValidateArrayInit(
37953795 }
37963796 continue;
37973797 },
3798 .bitcast => {
3799 // %a = bitcast(*arr_ty, %array_base)
3800 // %b = ptr_elem_ptr(%a, %index)
3801 // %c = bitcast(*elem_ty, %b)
3802 // %d = store(%c, %val)
3803 if (air_datas[next_air_inst].ty_op.operand != elem_ptr_air_ref) {
3804 array_is_comptime = false;
3805 continue;
3806 }
3807 const store_inst = block.instructions.items[block_index + 2];
3808 if (air_tags[store_inst] != .store) {
3809 array_is_comptime = false;
3810 continue;
3811 }
3812 const bin_op = air_datas[store_inst].bin_op;
3813 if (bin_op.lhs != Air.indexToRef(next_air_inst)) {
3814 array_is_comptime = false;
3815 continue;
3816 }
3817 if (try sema.resolveMaybeUndefValAllowVariables(block, elem_src, bin_op.rhs)) |val| {
3818 element_vals[i] = val;
3819 } else {
3820 array_is_comptime = false;
3821 }
3822 continue;
3823 },
37983824 else => {
37993825 array_is_comptime = false;
38003826 continue;
......@@ -21772,7 +21798,7 @@ fn coerceTupleToArray(
2177221798) !Air.Inst.Ref {
2177321799 const inst_ty = sema.typeOf(inst);
2177421800 const inst_len = inst_ty.arrayLen();
21775 const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen());
21801 const dest_len = dest_ty.arrayLen();
2177621802
2177721803 if (dest_len != inst_len) {
2177821804 const msg = msg: {
......@@ -21787,13 +21813,19 @@ fn coerceTupleToArray(
2178721813 return sema.failWithOwnedErrorMsg(block, msg);
2178821814 }
2178921815
21790 const element_vals = try sema.arena.alloc(Value, dest_len);
21791 const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_len);
21816 const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLenIncludingSentinel());
21817 const element_vals = try sema.arena.alloc(Value, dest_elems);
21818 const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_elems);
2179221819 const dest_elem_ty = dest_ty.childType();
2179321820
2179421821 var runtime_src: ?LazySrcLoc = null;
2179521822 for (element_vals) |*elem, i_usize| {
2179621823 const i = @intCast(u32, i_usize);
21824 if (i_usize == inst_len) {
21825 elem.* = dest_ty.sentinel().?;
21826 element_refs[i] = try sema.addConstant(dest_elem_ty, elem.*);
21827 break;
21828 }
2179721829 const elem_src = inst_src; // TODO better source location
2179821830 const elem_ref = try tupleField(sema, block, inst_src, inst, elem_src, i);
2179921831 const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src);
src/value.zig+1-1
......@@ -2186,7 +2186,7 @@ pub const Value = extern union {
21862186 // A tuple can be represented with .empty_struct_value,
21872187 // the_one_possible_value, .aggregate in which case we could
21882188 // end up here and the values are equal if the type has zero fields.
2189 return ty.structFieldCount() != 0;
2189 return ty.isTupleOrAnonStruct() and ty.structFieldCount() != 0;
21902190 },
21912191 .Float => {
21922192 const a_nan = a.isNan();
test/behavior/array.zig+11
......@@ -582,3 +582,14 @@ test "array with comptime only element type" {
582582 try testing.expect(a[0] == u32);
583583 try testing.expect(a[1] == i32);
584584}
585
586test "tuple to array handles sentinel" {
587 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
588 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
589
590 const S = struct {
591 const a = .{ 1, 2, 3 };
592 var b: [3:0]u8 = a;
593 };
594 try expect(S.b[0] == 1);
595}