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 {...@@ -1330,7 +1330,6 @@ fn testStaticBitSet(comptime Set: type) !void {
1330}1330}
13311331
1332test "IntegerBitSet" {1332test "IntegerBitSet" {
1333 if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
1334 try testStaticBitSet(IntegerBitSet(0));1333 try testStaticBitSet(IntegerBitSet(0));
1335 try testStaticBitSet(IntegerBitSet(1));1334 try testStaticBitSet(IntegerBitSet(1));
1336 try testStaticBitSet(IntegerBitSet(2));1335 try testStaticBitSet(IntegerBitSet(2));
...@@ -1342,7 +1341,6 @@ test "IntegerBitSet" {...@@ -1342,7 +1341,6 @@ test "IntegerBitSet" {
1342}1341}
13431342
1344test "ArrayBitSet" {1343test "ArrayBitSet" {
1345 if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
1346 if (@import("builtin").cpu.arch == .aarch64) {1344 if (@import("builtin").cpu.arch == .aarch64) {
1347 // https://github.com/ziglang/zig/issues/98791345 // https://github.com/ziglang/zig/issues/9879
1348 return error.SkipZigTest;1346 return error.SkipZigTest;
...@@ -1357,7 +1355,6 @@ test "ArrayBitSet" {...@@ -1357,7 +1355,6 @@ test "ArrayBitSet" {
1357}1355}
13581356
1359test "DynamicBitSetUnmanaged" {1357test "DynamicBitSetUnmanaged" {
1360 if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
1361 const allocator = std.testing.allocator;1358 const allocator = std.testing.allocator;
1362 var a = try DynamicBitSetUnmanaged.initEmpty(allocator, 300);1359 var a = try DynamicBitSetUnmanaged.initEmpty(allocator, 300);
1363 try testing.expectEqual(@as(usize, 0), a.count());1360 try testing.expectEqual(@as(usize, 0), a.count());
...@@ -1398,7 +1395,6 @@ test "DynamicBitSetUnmanaged" {...@@ -1398,7 +1395,6 @@ test "DynamicBitSetUnmanaged" {
1398}1395}
13991396
1400test "DynamicBitSet" {1397test "DynamicBitSet" {
1401 if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
1402 const allocator = std.testing.allocator;1398 const allocator = std.testing.allocator;
1403 var a = try DynamicBitSet.initEmpty(allocator, 300);1399 var a = try DynamicBitSet.initEmpty(allocator, 300);
1404 try testing.expectEqual(@as(usize, 0), a.count());1400 try testing.expectEqual(@as(usize, 0), a.count());
lib/std/tz.zig+1-4
...@@ -11,7 +11,7 @@ pub const Timetype = struct {...@@ -11,7 +11,7 @@ pub const Timetype = struct {
11 flags: u8,11 flags: u8,
12 name_data: [6:0]u8,12 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 {
15 return std.mem.sliceTo(self.name_data[0..], 0);15 return std.mem.sliceTo(self.name_data[0..], 0);
16 }16 }
1717
...@@ -214,7 +214,6 @@ pub const Tz = struct {...@@ -214,7 +214,6 @@ pub const Tz = struct {
214};214};
215215
216test "slim" {216test "slim" {
217 if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
218 const data = @embedFile("tz/asia_tokyo.tzif");217 const data = @embedFile("tz/asia_tokyo.tzif");
219 var in_stream = std.io.fixedBufferStream(data);218 var in_stream = std.io.fixedBufferStream(data);
220219
...@@ -228,7 +227,6 @@ test "slim" {...@@ -228,7 +227,6 @@ test "slim" {
228}227}
229228
230test "fat" {229test "fat" {
231 if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
232 const data = @embedFile("tz/antarctica_davis.tzif");230 const data = @embedFile("tz/antarctica_davis.tzif");
233 var in_stream = std.io.fixedBufferStream(data);231 var in_stream = std.io.fixedBufferStream(data);
234232
...@@ -241,7 +239,6 @@ test "fat" {...@@ -241,7 +239,6 @@ test "fat" {
241}239}
242240
243test "legacy" {241test "legacy" {
244 if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
245 // Taken from Slackware 8.0, from 2001242 // Taken from Slackware 8.0, from 2001
246 const data = @embedFile("tz/europe_vatican.tzif");243 const data = @embedFile("tz/europe_vatican.tzif");
247 var in_stream = std.io.fixedBufferStream(data);244 var in_stream = std.io.fixedBufferStream(data);
src/Sema.zig+35-3
...@@ -3795,6 +3795,32 @@ fn zirValidateArrayInit(...@@ -3795,6 +3795,32 @@ fn zirValidateArrayInit(
3795 }3795 }
3796 continue;3796 continue;
3797 },3797 },
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 },
3798 else => {3824 else => {
3799 array_is_comptime = false;3825 array_is_comptime = false;
3800 continue;3826 continue;
...@@ -21772,7 +21798,7 @@ fn coerceTupleToArray(...@@ -21772,7 +21798,7 @@ fn coerceTupleToArray(
21772) !Air.Inst.Ref {21798) !Air.Inst.Ref {
21773 const inst_ty = sema.typeOf(inst);21799 const inst_ty = sema.typeOf(inst);
21774 const inst_len = inst_ty.arrayLen();21800 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
21777 if (dest_len != inst_len) {21803 if (dest_len != inst_len) {
21778 const msg = msg: {21804 const msg = msg: {
...@@ -21787,13 +21813,19 @@ fn coerceTupleToArray(...@@ -21787,13 +21813,19 @@ fn coerceTupleToArray(
21787 return sema.failWithOwnedErrorMsg(block, msg);21813 return sema.failWithOwnedErrorMsg(block, msg);
21788 }21814 }
2178921815
21790 const element_vals = try sema.arena.alloc(Value, dest_len);21816 const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLenIncludingSentinel());
21791 const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_len);21817 const element_vals = try sema.arena.alloc(Value, dest_elems);
21818 const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_elems);
21792 const dest_elem_ty = dest_ty.childType();21819 const dest_elem_ty = dest_ty.childType();
2179321820
21794 var runtime_src: ?LazySrcLoc = null;21821 var runtime_src: ?LazySrcLoc = null;
21795 for (element_vals) |*elem, i_usize| {21822 for (element_vals) |*elem, i_usize| {
21796 const i = @intCast(u32, i_usize);21823 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 }
21797 const elem_src = inst_src; // TODO better source location21829 const elem_src = inst_src; // TODO better source location
21798 const elem_ref = try tupleField(sema, block, inst_src, inst, elem_src, i);21830 const elem_ref = try tupleField(sema, block, inst_src, inst, elem_src, i);
21799 const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src);21831 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 {...@@ -2186,7 +2186,7 @@ pub const Value = extern union {
2186 // A tuple can be represented with .empty_struct_value,2186 // A tuple can be represented with .empty_struct_value,
2187 // the_one_possible_value, .aggregate in which case we could2187 // the_one_possible_value, .aggregate in which case we could
2188 // end up here and the values are equal if the type has zero fields.2188 // 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;
2190 },2190 },
2191 .Float => {2191 .Float => {
2192 const a_nan = a.isNan();2192 const a_nan = a.isNan();
test/behavior/array.zig+11
...@@ -582,3 +582,14 @@ test "array with comptime only element type" {...@@ -582,3 +582,14 @@ test "array with comptime only element type" {
582 try testing.expect(a[0] == u32);582 try testing.expect(a[0] == u32);
583 try testing.expect(a[1] == i32);583 try testing.expect(a[1] == i32);
584}584}
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}