| author | |
| committer | |
| log | 4c83b11f71564e0de80f496f471ca6dfb83a95e3 |
| tree | 74169b63dd4334421f353e947ad90dddff672ac7 |
| parent | 02a43f325bfbccb73fb773f15b162d531c3c3ada |
| parent | dbe0d3d5790d9e21cf42696d4cea8cc477207592 |
| signature |
Stage2 fixes13 files changed, 83 insertions(+), 31 deletions(-)
lib/std/math/big/int.zig+2-1| ... | ... | @@ -2063,7 +2063,8 @@ pub const Const = struct { |
| 2063 | 2063 | // This is the inverse of calcDivLimbsBufferLen |
| 2064 | 2064 | const available_len = (limbs.len / 3) - 2; |
| 2065 | 2065 | |
| 2066 | const biggest: Const = .{ | |
| 2066 | // TODO https://github.com/ziglang/zig/issues/11439 | |
| 2067 | const biggest = comptime Const{ | |
| 2067 | 2068 | .limbs = &([1]Limb{math.maxInt(Limb)} ** available_len), |
| 2068 | 2069 | .positive = false, |
| 2069 | 2070 | }; |
lib/std/os/linux/x86_64.zig+6-1| ... | ... | @@ -100,7 +100,12 @@ pub fn syscall6( |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /// This matches the libc clone function. |
| 103 | pub extern fn clone(func: fn (arg: usize) callconv(.C) u8, stack: usize, flags: usize, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize; | |
| 103 | pub extern fn clone(func: CloneFn, stack: usize, flags: usize, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize; | |
| 104 | ||
| 105 | const CloneFn = switch (@import("builtin").zig_backend) { | |
| 106 | .stage1 => fn (arg: usize) callconv(.C) u8, | |
| 107 | else => *const fn (arg: usize) callconv(.C) u8, | |
| 108 | }; | |
| 104 | 109 | |
| 105 | 110 | pub const restore = restore_rt; |
| 106 | 111 |
src/AstGen.zig+5| ... | ... | @@ -2851,6 +2851,9 @@ fn varDecl( |
| 2851 | 2851 | return &sub_scope.base; |
| 2852 | 2852 | }, |
| 2853 | 2853 | .keyword_var => { |
| 2854 | const old_rl_ty_inst = gz.rl_ty_inst; | |
| 2855 | defer gz.rl_ty_inst = old_rl_ty_inst; | |
| 2856 | ||
| 2854 | 2857 | const is_comptime = var_decl.comptime_token != null or gz.force_comptime; |
| 2855 | 2858 | var resolve_inferred_alloc: Zir.Inst.Ref = .none; |
| 2856 | 2859 | const var_data: struct { |
| ... | ... | @@ -2875,6 +2878,7 @@ fn varDecl( |
| 2875 | 2878 | }); |
| 2876 | 2879 | } |
| 2877 | 2880 | }; |
| 2881 | gz.rl_ty_inst = type_inst; | |
| 2878 | 2882 | break :a .{ .alloc = alloc, .result_loc = .{ .ptr = alloc } }; |
| 2879 | 2883 | } else a: { |
| 2880 | 2884 | const alloc = alloc: { |
| ... | ... | @@ -2894,6 +2898,7 @@ fn varDecl( |
| 2894 | 2898 | }); |
| 2895 | 2899 | } |
| 2896 | 2900 | }; |
| 2901 | gz.rl_ty_inst = .none; | |
| 2897 | 2902 | resolve_inferred_alloc = alloc; |
| 2898 | 2903 | break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } }; |
| 2899 | 2904 | }; |
src/Sema.zig+33-16| ... | ... | @@ -12432,7 +12432,8 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 12432 | 12432 | const tracy = trace(@src()); |
| 12433 | 12433 | defer tracy.end(); |
| 12434 | 12434 | |
| 12435 | const src: LazySrcLoc = .unneeded; | |
| 12435 | // TODO better source location | |
| 12436 | const src: LazySrcLoc = sema.src; | |
| 12436 | 12437 | const elem_ty_src: LazySrcLoc = .unneeded; |
| 12437 | 12438 | const inst_data = sema.code.instructions.items(.data)[inst].ptr_type; |
| 12438 | 12439 | const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index); |
| ... | ... | @@ -13086,22 +13087,38 @@ fn fieldType( |
| 13086 | 13087 | ) CompileError!Air.Inst.Ref { |
| 13087 | 13088 | const resolved_ty = try sema.resolveTypeFields(block, ty_src, aggregate_ty); |
| 13088 | 13089 | const target = sema.mod.getTarget(); |
| 13089 | switch (resolved_ty.zigTypeTag()) { | |
| 13090 | .Struct => { | |
| 13091 | const struct_obj = resolved_ty.castTag(.@"struct").?.data; | |
| 13092 | const field = struct_obj.fields.get(field_name) orelse | |
| 13093 | return sema.failWithBadStructFieldAccess(block, struct_obj, field_src, field_name); | |
| 13094 | return sema.addType(field.ty); | |
| 13095 | }, | |
| 13096 | .Union => { | |
| 13097 | const union_obj = resolved_ty.cast(Type.Payload.Union).?.data; | |
| 13098 | const field = union_obj.fields.get(field_name) orelse | |
| 13099 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name); | |
| 13100 | return sema.addType(field.ty); | |
| 13101 | }, | |
| 13102 | else => return sema.fail(block, ty_src, "expected struct or union; found '{}'", .{ | |
| 13090 | var cur_ty = resolved_ty; | |
| 13091 | while (true) { | |
| 13092 | switch (cur_ty.zigTypeTag()) { | |
| 13093 | .Struct => { | |
| 13094 | const struct_obj = cur_ty.castTag(.@"struct").?.data; | |
| 13095 | const field = struct_obj.fields.get(field_name) orelse | |
| 13096 | return sema.failWithBadStructFieldAccess(block, struct_obj, field_src, field_name); | |
| 13097 | return sema.addType(field.ty); | |
| 13098 | }, | |
| 13099 | .Union => { | |
| 13100 | const union_obj = cur_ty.cast(Type.Payload.Union).?.data; | |
| 13101 | const field = union_obj.fields.get(field_name) orelse | |
| 13102 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name); | |
| 13103 | return sema.addType(field.ty); | |
| 13104 | }, | |
| 13105 | .Optional => { | |
| 13106 | if (cur_ty.castTag(.optional)) |some| { | |
| 13107 | // Struct/array init through optional requires the child type to not be a pointer. | |
| 13108 | // If the child of .optional is a pointer it'll error on the next loop. | |
| 13109 | cur_ty = some.data; | |
| 13110 | continue; | |
| 13111 | } | |
| 13112 | }, | |
| 13113 | .ErrorUnion => { | |
| 13114 | cur_ty = cur_ty.errorUnionPayload(); | |
| 13115 | continue; | |
| 13116 | }, | |
| 13117 | else => {}, | |
| 13118 | } | |
| 13119 | return sema.fail(block, ty_src, "expected struct or union; found '{}'", .{ | |
| 13103 | 13120 | resolved_ty.fmt(target), |
| 13104 | }), | |
| 13121 | }); | |
| 13105 | 13122 | } |
| 13106 | 13123 | } |
| 13107 | 13124 |
src/arch/sparcv9/CodeGen.zig+3-3| ... | ... | @@ -624,9 +624,9 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void { |
| 624 | 624 | const is_volatile = (extra.data.flags & 0x80000000) != 0; |
| 625 | 625 | const clobbers_len = @truncate(u31, extra.data.flags); |
| 626 | 626 | var extra_i: usize = extra.end; |
| 627 | const outputs = @bitCast([]const Air.Inst.Ref, self.air.extra[extra_i .. extra_i + extra.data.outputs_len]); | |
| 627 | const outputs = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra_i .. extra_i + extra.data.outputs_len]); | |
| 628 | 628 | extra_i += outputs.len; |
| 629 | const inputs = @bitCast([]const Air.Inst.Ref, self.air.extra[extra_i .. extra_i + extra.data.inputs_len]); | |
| 629 | const inputs = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra_i .. extra_i + extra.data.inputs_len]); | |
| 630 | 630 | extra_i += inputs.len; |
| 631 | 631 | |
| 632 | 632 | const dead = !is_volatile and self.liveness.isUnused(inst); |
| ... | ... | @@ -826,7 +826,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions. |
| 826 | 826 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; |
| 827 | 827 | const callee = pl_op.operand; |
| 828 | 828 | const extra = self.air.extraData(Air.Call, pl_op.payload); |
| 829 | const args = @bitCast([]const Air.Inst.Ref, self.air.extra[extra.end .. extra.end + extra.data.args_len]); | |
| 829 | const args = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra.end .. extra.end + extra.data.args_len]); | |
| 830 | 830 | const ty = self.air.typeOf(callee); |
| 831 | 831 | const fn_ty = switch (ty.zigTypeTag()) { |
| 832 | 832 | .Fn => ty, |
src/codegen/llvm.zig+1| ... | ... | @@ -4637,6 +4637,7 @@ pub const FuncGen = struct { |
| 4637 | 4637 | switch (state) { |
| 4638 | 4638 | .start => switch (byte) { |
| 4639 | 4639 | '%' => state = .percent, |
| 4640 | '$' => try rendered_template.appendSlice("$$"), | |
| 4640 | 4641 | else => try rendered_template.append(byte), |
| 4641 | 4642 | }, |
| 4642 | 4643 | .percent => switch (byte) { |
src/link/MachO.zig+7-4| ... | ... | @@ -1317,6 +1317,9 @@ pub fn parseDylib(self: *MachO, path: []const u8, opts: DylibCreateOpts) ParseDy |
| 1317 | 1317 | error.EndOfStream, error.NotDylib => { |
| 1318 | 1318 | try file.seekTo(0); |
| 1319 | 1319 | |
| 1320 | // TODO https://github.com/ziglang/zig/issues/11367 | |
| 1321 | if (@import("builtin").zig_backend != .stage1) return error.Unexpected; | |
| 1322 | ||
| 1320 | 1323 | var lib_stub = LibStub.loadFromFile(self.base.allocator, file) catch { |
| 1321 | 1324 | dylib.deinit(self.base.allocator); |
| 1322 | 1325 | return false; |
| ... | ... | @@ -5747,7 +5750,6 @@ fn populateLazyBindOffsetsInStubHelper(self: *MachO, buffer: []const u8) !void { |
| 5747 | 5750 | while (true) { |
| 5748 | 5751 | const inst = reader.readByte() catch |err| switch (err) { |
| 5749 | 5752 | error.EndOfStream => break, |
| 5750 | else => return err, | |
| 5751 | 5753 | }; |
| 5752 | 5754 | const opcode: u8 = inst & macho.BIND_OPCODE_MASK; |
| 5753 | 5755 | |
| ... | ... | @@ -5875,7 +5877,7 @@ fn writeFunctionStarts(self: *MachO) !void { |
| 5875 | 5877 | mem.set(u8, buffer, 0); |
| 5876 | 5878 | |
| 5877 | 5879 | var stream = std.io.fixedBufferStream(buffer); |
| 5878 | var writer = stream.writer(); | |
| 5880 | const writer = stream.writer(); | |
| 5879 | 5881 | |
| 5880 | 5882 | for (offsets.items) |offset| { |
| 5881 | 5883 | try std.leb.writeULEB128(writer, offset); |
| ... | ... | @@ -6236,7 +6238,8 @@ fn writeLoadCommands(self: *MachO) !void { |
| 6236 | 6238 | |
| 6237 | 6239 | var buffer = try self.base.allocator.alloc(u8, sizeofcmds); |
| 6238 | 6240 | defer self.base.allocator.free(buffer); |
| 6239 | var writer = std.io.fixedBufferStream(buffer).writer(); | |
| 6241 | var fib = std.io.fixedBufferStream(buffer); | |
| 6242 | const writer = fib.writer(); | |
| 6240 | 6243 | for (self.load_commands.items) |lc| { |
| 6241 | 6244 | try lc.write(writer); |
| 6242 | 6245 | } |
| ... | ... | @@ -6416,7 +6419,7 @@ fn snapshotState(self: *MachO) !void { |
| 6416 | 6419 | error.Unseekable => try out_file.writer().writeByte('['), |
| 6417 | 6420 | else => |e| return e, |
| 6418 | 6421 | } |
| 6419 | var writer = out_file.writer(); | |
| 6422 | const writer = out_file.writer(); | |
| 6420 | 6423 | |
| 6421 | 6424 | var snapshot = Snapshot{ |
| 6422 | 6425 | .timestamp = std.time.nanoTimestamp(), |
src/link/MachO/Archive.zig-1| ... | ... | @@ -171,7 +171,6 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) ! |
| 171 | 171 | while (true) { |
| 172 | 172 | const n_strx = symtab_reader.readIntLittle(u32) catch |err| switch (err) { |
| 173 | 173 | error.EndOfStream => break, |
| 174 | else => |e| return e, | |
| 175 | 174 | }; |
| 176 | 175 | const object_offset = try symtab_reader.readIntLittle(u32); |
| 177 | 176 |
src/link/MachO/DebugSymbols.zig+2-1| ... | ... | @@ -472,7 +472,8 @@ fn writeLoadCommands(self: *DebugSymbols, allocator: Allocator) !void { |
| 472 | 472 | |
| 473 | 473 | var buffer = try allocator.alloc(u8, sizeofcmds); |
| 474 | 474 | defer allocator.free(buffer); |
| 475 | var writer = std.io.fixedBufferStream(buffer).writer(); | |
| 475 | var fib = std.io.fixedBufferStream(buffer); | |
| 476 | const writer = fib.writer(); | |
| 476 | 477 | for (self.load_commands.items) |lc| { |
| 477 | 478 | try lc.write(writer); |
| 478 | 479 | } |
src/link/MachO/Dylib.zig+1-1| ... | ... | @@ -64,7 +64,7 @@ pub const Id = struct { |
| 64 | 64 | }; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | pub fn deinit(id: *Id, allocator: Allocator) void { | |
| 67 | pub fn deinit(id: Id, allocator: Allocator) void { | |
| 68 | 68 | allocator.free(id.name); |
| 69 | 69 | } |
| 70 | 70 |
src/link/MachO/Object.zig+2-1| ... | ... | @@ -492,7 +492,8 @@ pub fn parseIntoAtoms(self: *Object, allocator: Allocator, macho_file: *MachO) ! |
| 492 | 492 | mem.copy(u8, atom.code.items, code); |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | try atom.parseRelocs(relocs, .{ | |
| 495 | // TODO stage2 bug: @alignCast shouldn't be needed | |
| 496 | try atom.parseRelocs(@alignCast(@alignOf(macho.relocation_info), relocs), .{ | |
| 496 | 497 | .base_addr = sect.addr, |
| 497 | 498 | .allocator = allocator, |
| 498 | 499 | .object = self, |
src/link/Wasm/Object.zig+2-1| ... | ... | @@ -312,7 +312,8 @@ fn Parser(comptime ReaderType: type) type { |
| 312 | 312 | var section_index: u32 = 0; |
| 313 | 313 | while (self.reader.reader().readByte()) |byte| : (section_index += 1) { |
| 314 | 314 | const len = try readLeb(u32, self.reader.reader()); |
| 315 | const reader = std.io.limitedReader(self.reader.reader(), len).reader(); | |
| 315 | var limited_reader = std.io.limitedReader(self.reader.reader(), len); | |
| 316 | const reader = limited_reader.reader(); | |
| 316 | 317 | switch (@intToEnum(std.wasm.Section, byte)) { |
| 317 | 318 | .custom => { |
| 318 | 319 | const name_len = try readLeb(u32, reader); |
test/behavior/basic.zig+19-1| ... | ... | @@ -859,7 +859,6 @@ test "catch in block has correct result location" { |
| 859 | 859 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| 860 | 860 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 861 | 861 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 862 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | |
| 863 | 862 | |
| 864 | 863 | const S = struct { |
| 865 | 864 | fn open() error{A}!@This() { |
| ... | ... | @@ -887,3 +886,22 @@ test "labeled block with runtime branch forwards its result location type to bre |
| 887 | 886 | }; |
| 888 | 887 | try expect(e == .b); |
| 889 | 888 | } |
| 889 | ||
| 890 | test "try in labeled block doesn't cast to wrong type" { | |
| 891 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | |
| 892 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | |
| 893 | ||
| 894 | const S = struct { | |
| 895 | a: u32, | |
| 896 | fn foo() anyerror!u32 { | |
| 897 | return 1; | |
| 898 | } | |
| 899 | }; | |
| 900 | const s: ?*S = blk: { | |
| 901 | var a = try S.foo(); | |
| 902 | ||
| 903 | _ = a; | |
| 904 | break :blk null; | |
| 905 | }; | |
| 906 | _ = s; | |
| 907 | } |