| author | |
| committer | |
| log | 3708e26f4b8b9514f055ae2a0571d3290414bf8b |
| tree | ee2745845554a96546bd4358f9e17ed634f7a3da |
| parent | 2eaef84ebe968224b0cf25206abf12ea1c5e0f5a |
| parent | 6ab5219e34d385e29df9b2a014ed89b9db343740 |
| signature |
stage2 bug fixes6 files changed, 54 insertions(+), 30 deletions(-)
lib/std/io/c_writer.zig+1-1| ... | @@ -30,7 +30,7 @@ fn cWriterWrite(c_file: *std.c.FILE, bytes: []const u8) std.fs.File.WriteError!u | ... | @@ -30,7 +30,7 @@ fn cWriterWrite(c_file: *std.c.FILE, bytes: []const u8) std.fs.File.WriteError!u |
| 30 | } | 30 | } |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | test { | 33 | test "C Writer" { |
| 34 | if (!builtin.link_libc or builtin.os.tag == .wasi) return error.SkipZigTest; | 34 | if (!builtin.link_libc or builtin.os.tag == .wasi) return error.SkipZigTest; |
| 35 | 35 | ||
| 36 | const filename = "tmp_io_test_file.txt"; | 36 | const filename = "tmp_io_test_file.txt"; |
lib/std/mem.zig+20-12| ... | @@ -2831,6 +2831,8 @@ pub fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr)) { | ... | @@ -2831,6 +2831,8 @@ pub fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr)) { |
| 2831 | } | 2831 | } |
| 2832 | 2832 | ||
| 2833 | test "asBytes" { | 2833 | test "asBytes" { |
| 2834 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; | ||
| 2835 | |||
| 2834 | const deadbeef = @as(u32, 0xDEADBEEF); | 2836 | const deadbeef = @as(u32, 0xDEADBEEF); |
| 2835 | const deadbeef_bytes = switch (native_endian) { | 2837 | const deadbeef_bytes = switch (native_endian) { |
| 2836 | .Big => "\xDE\xAD\xBE\xEF", | 2838 | .Big => "\xDE\xAD\xBE\xEF", |
| ... | @@ -2857,7 +2859,14 @@ test "asBytes" { | ... | @@ -2857,7 +2859,14 @@ test "asBytes" { |
| 2857 | .c = 0xDE, | 2859 | .c = 0xDE, |
| 2858 | .d = 0xA1, | 2860 | .d = 0xA1, |
| 2859 | }; | 2861 | }; |
| 2860 | try testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1")); | 2862 | switch (native_endian) { |
| 2863 | .Little => { | ||
| 2864 | try testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1")); | ||
| 2865 | }, | ||
| 2866 | .Big => { | ||
| 2867 | try testing.expect(eql(u8, asBytes(&inst), "\xA1\xDE\xEF\xBE")); | ||
| 2868 | }, | ||
| 2869 | } | ||
| 2861 | 2870 | ||
| 2862 | const ZST = struct {}; | 2871 | const ZST = struct {}; |
| 2863 | const zero = ZST{}; | 2872 | const zero = ZST{}; |
| ... | @@ -2917,6 +2926,8 @@ pub fn bytesAsValue(comptime T: type, bytes: anytype) BytesAsValueReturnType(T, | ... | @@ -2917,6 +2926,8 @@ pub fn bytesAsValue(comptime T: type, bytes: anytype) BytesAsValueReturnType(T, |
| 2917 | } | 2926 | } |
| 2918 | 2927 | ||
| 2919 | test "bytesAsValue" { | 2928 | test "bytesAsValue" { |
| 2929 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; | ||
| 2930 | |||
| 2920 | const deadbeef = @as(u32, 0xDEADBEEF); | 2931 | const deadbeef = @as(u32, 0xDEADBEEF); |
| 2921 | const deadbeef_bytes = switch (native_endian) { | 2932 | const deadbeef_bytes = switch (native_endian) { |
| 2922 | .Big => "\xDE\xAD\xBE\xEF", | 2933 | .Big => "\xDE\xAD\xBE\xEF", |
| ... | @@ -2948,7 +2959,10 @@ test "bytesAsValue" { | ... | @@ -2948,7 +2959,10 @@ test "bytesAsValue" { |
| 2948 | .c = 0xDE, | 2959 | .c = 0xDE, |
| 2949 | .d = 0xA1, | 2960 | .d = 0xA1, |
| 2950 | }; | 2961 | }; |
| 2951 | const inst_bytes = "\xBE\xEF\xDE\xA1"; | 2962 | const inst_bytes = switch (native_endian) { |
| 2963 | .Little => "\xBE\xEF\xDE\xA1", | ||
| 2964 | .Big => "\xA1\xDE\xEF\xBE", | ||
| 2965 | }; | ||
| 2952 | const inst2 = bytesAsValue(S, inst_bytes); | 2966 | const inst2 = bytesAsValue(S, inst_bytes); |
| 2953 | try testing.expect(meta.eql(inst, inst2.*)); | 2967 | try testing.expect(meta.eql(inst, inst2.*)); |
| 2954 | } | 2968 | } |
| ... | @@ -3115,6 +3129,8 @@ test "sliceAsBytes with sentinel slice" { | ... | @@ -3115,6 +3129,8 @@ test "sliceAsBytes with sentinel slice" { |
| 3115 | } | 3129 | } |
| 3116 | 3130 | ||
| 3117 | test "sliceAsBytes packed struct at runtime and comptime" { | 3131 | test "sliceAsBytes packed struct at runtime and comptime" { |
| 3132 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; | ||
| 3133 | |||
| 3118 | const Foo = packed struct { | 3134 | const Foo = packed struct { |
| 3119 | a: u4, | 3135 | a: u4, |
| 3120 | b: u4, | 3136 | b: u4, |
| ... | @@ -3124,16 +3140,8 @@ test "sliceAsBytes packed struct at runtime and comptime" { | ... | @@ -3124,16 +3140,8 @@ test "sliceAsBytes packed struct at runtime and comptime" { |
| 3124 | var foo: Foo = undefined; | 3140 | var foo: Foo = undefined; |
| 3125 | var slice = sliceAsBytes(@as(*[1]Foo, &foo)[0..1]); | 3141 | var slice = sliceAsBytes(@as(*[1]Foo, &foo)[0..1]); |
| 3126 | slice[0] = 0x13; | 3142 | slice[0] = 0x13; |
| 3127 | switch (native_endian) { | 3143 | try testing.expect(foo.a == 0x3); |
| 3128 | .Big => { | 3144 | try testing.expect(foo.b == 0x1); |
| 3129 | try testing.expect(foo.a == 0x1); | ||
| 3130 | try testing.expect(foo.b == 0x3); | ||
| 3131 | }, | ||
| 3132 | .Little => { | ||
| 3133 | try testing.expect(foo.a == 0x3); | ||
| 3134 | try testing.expect(foo.b == 0x1); | ||
| 3135 | }, | ||
| 3136 | } | ||
| 3137 | } | 3145 | } |
| 3138 | }; | 3146 | }; |
| 3139 | try S.doTheTest(); | 3147 | try S.doTheTest(); |
lib/std/x/net/bpf.zig+3-7| ... | @@ -706,12 +706,8 @@ fn expectFail(expected_error: anyerror, data: anytype, filter: []Insn) !void { | ... | @@ -706,12 +706,8 @@ fn expectFail(expected_error: anyerror, data: anytype, filter: []Insn) !void { |
| 706 | } | 706 | } |
| 707 | 707 | ||
| 708 | test "simulator coverage" { | 708 | test "simulator coverage" { |
| 709 | const some_data: packed struct { | 709 | const some_data = [_]u8{ |
| 710 | foo: u32, | 710 | 0xaa, 0xbb, 0xcc, 0xdd, 0x7f, |
| 711 | bar: u8, | ||
| 712 | } = .{ | ||
| 713 | .foo = mem.nativeToBig(u32, 0xaabbccdd), | ||
| 714 | .bar = 0x7f, | ||
| 715 | }; | 711 | }; |
| 716 | 712 | ||
| 717 | try expectPass(&some_data, &.{ | 713 | try expectPass(&some_data, &.{ |
| ... | @@ -764,7 +760,7 @@ test "simulator coverage" { | ... | @@ -764,7 +760,7 @@ test "simulator coverage" { |
| 764 | // ld #len | 760 | // ld #len |
| 765 | // fail if A != 5 | 761 | // fail if A != 5 |
| 766 | Insn.ld_len(), | 762 | Insn.ld_len(), |
| 767 | Insn.jmp(.jeq, .{ .k = @sizeOf(@TypeOf(some_data)) }, 1, 0), | 763 | Insn.jmp(.jeq, .{ .k = some_data.len }, 1, 0), |
| 768 | Insn.ret(.{ .k = 9 }), | 764 | Insn.ret(.{ .k = 9 }), |
| 769 | // ld #0 | 765 | // ld #0 |
| 770 | // ld arc4random() | 766 | // ld arc4random() |
src/Sema.zig+3-1| ... | @@ -7096,6 +7096,7 @@ fn funcCommon( | ... | @@ -7096,6 +7096,7 @@ fn funcCommon( |
| 7096 | if (param.ty.tag() == .generic_poison) is_generic = true; | 7096 | if (param.ty.tag() == .generic_poison) is_generic = true; |
| 7097 | } | 7097 | } |
| 7098 | 7098 | ||
| 7099 | var destroy_fn_on_error = false; | ||
| 7099 | const new_func: *Module.Fn = new_func: { | 7100 | const new_func: *Module.Fn = new_func: { |
| 7100 | if (!has_body) break :new_func undefined; | 7101 | if (!has_body) break :new_func undefined; |
| 7101 | if (sema.comptime_args_fn_inst == func_inst) { | 7102 | if (sema.comptime_args_fn_inst == func_inst) { |
| ... | @@ -7103,9 +7104,10 @@ fn funcCommon( | ... | @@ -7103,9 +7104,10 @@ fn funcCommon( |
| 7103 | sema.preallocated_new_func = null; // take ownership | 7104 | sema.preallocated_new_func = null; // take ownership |
| 7104 | break :new_func new_func; | 7105 | break :new_func new_func; |
| 7105 | } | 7106 | } |
| 7107 | destroy_fn_on_error = true; | ||
| 7106 | break :new_func try sema.gpa.create(Module.Fn); | 7108 | break :new_func try sema.gpa.create(Module.Fn); |
| 7107 | }; | 7109 | }; |
| 7108 | errdefer if (has_body) sema.gpa.destroy(new_func); | 7110 | errdefer if (destroy_fn_on_error) sema.gpa.destroy(new_func); |
| 7109 | 7111 | ||
| 7110 | var maybe_inferred_error_set_node: ?*Module.Fn.InferredErrorSetListNode = null; | 7112 | var maybe_inferred_error_set_node: ?*Module.Fn.InferredErrorSetListNode = null; |
| 7111 | errdefer if (maybe_inferred_error_set_node) |node| sema.gpa.destroy(node); | 7113 | errdefer if (maybe_inferred_error_set_node) |node| sema.gpa.destroy(node); |
src/codegen/llvm.zig+26-9| ... | @@ -5244,7 +5244,7 @@ pub const FuncGen = struct { | ... | @@ -5244,7 +5244,7 @@ pub const FuncGen = struct { |
| 5244 | const operand_ty = self.air.typeOf(pl_op.operand); | 5244 | const operand_ty = self.air.typeOf(pl_op.operand); |
| 5245 | const name = self.air.nullTerminatedString(pl_op.payload); | 5245 | const name = self.air.nullTerminatedString(pl_op.payload); |
| 5246 | 5246 | ||
| 5247 | if (needDbgVarWorkaround(self.dg, operand_ty)) { | 5247 | if (needDbgVarWorkaround(self.dg)) { |
| 5248 | return null; | 5248 | return null; |
| 5249 | } | 5249 | } |
| 5250 | 5250 | ||
| ... | @@ -5432,6 +5432,25 @@ pub const FuncGen = struct { | ... | @@ -5432,6 +5432,25 @@ pub const FuncGen = struct { |
| 5432 | total_i += 1; | 5432 | total_i += 1; |
| 5433 | } | 5433 | } |
| 5434 | } | 5434 | } |
| 5435 | |||
| 5436 | // For some targets, Clang unconditionally adds some clobbers to all inline assembly. | ||
| 5437 | // While this is probably not strictly necessary, if we don't follow Clang's lead | ||
| 5438 | // here then we may risk tripping LLVM bugs since anything not used by Clang tends | ||
| 5439 | // to be buggy and regress often. | ||
| 5440 | switch (target.cpu.arch) { | ||
| 5441 | .x86_64, .i386 => { | ||
| 5442 | if (total_i != 0) try llvm_constraints.append(self.gpa, ','); | ||
| 5443 | try llvm_constraints.appendSlice(self.gpa, "~{dirflag},~{fpsr},~{flags}"); | ||
| 5444 | total_i += 3; | ||
| 5445 | }, | ||
| 5446 | .mips, .mipsel, .mips64, .mips64el => { | ||
| 5447 | if (total_i != 0) try llvm_constraints.append(self.gpa, ','); | ||
| 5448 | try llvm_constraints.appendSlice(self.gpa, "~{$1}"); | ||
| 5449 | total_i += 1; | ||
| 5450 | }, | ||
| 5451 | else => {}, | ||
| 5452 | } | ||
| 5453 | |||
| 5435 | const asm_source = std.mem.sliceAsBytes(self.air.extra[extra_i..])[0..extra.data.source_len]; | 5454 | const asm_source = std.mem.sliceAsBytes(self.air.extra[extra_i..])[0..extra.data.source_len]; |
| 5436 | 5455 | ||
| 5437 | // hackety hacks until stage2 has proper inline asm in the frontend. | 5456 | // hackety hacks until stage2 has proper inline asm in the frontend. |
| ... | @@ -6988,7 +7007,7 @@ pub const FuncGen = struct { | ... | @@ -6988,7 +7007,7 @@ pub const FuncGen = struct { |
| 6988 | 7007 | ||
| 6989 | const inst_ty = self.air.typeOfIndex(inst); | 7008 | const inst_ty = self.air.typeOfIndex(inst); |
| 6990 | if (self.dg.object.di_builder) |dib| { | 7009 | if (self.dg.object.di_builder) |dib| { |
| 6991 | if (needDbgVarWorkaround(self.dg, inst_ty)) { | 7010 | if (needDbgVarWorkaround(self.dg)) { |
| 6992 | return arg_val; | 7011 | return arg_val; |
| 6993 | } | 7012 | } |
| 6994 | 7013 | ||
| ... | @@ -9255,13 +9274,11 @@ const AnnotatedDITypePtr = enum(usize) { | ... | @@ -9255,13 +9274,11 @@ const AnnotatedDITypePtr = enum(usize) { |
| 9255 | const lt_errors_fn_name = "__zig_lt_errors_len"; | 9274 | const lt_errors_fn_name = "__zig_lt_errors_len"; |
| 9256 | 9275 | ||
| 9257 | /// Without this workaround, LLVM crashes with "unknown codeview register H1" | 9276 | /// Without this workaround, LLVM crashes with "unknown codeview register H1" |
| 9258 | /// TODO use llvm-reduce and file upstream LLVM bug for this. | 9277 | /// https://github.com/llvm/llvm-project/issues/56484 |
| 9259 | fn needDbgVarWorkaround(dg: *DeclGen, ty: Type) bool { | 9278 | fn needDbgVarWorkaround(dg: *DeclGen) bool { |
| 9260 | if (ty.tag() == .f16) { | 9279 | const target = dg.module.getTarget(); |
| 9261 | const target = dg.module.getTarget(); | 9280 | if (target.os.tag == .windows and target.cpu.arch == .aarch64) { |
| 9262 | if (target.os.tag == .windows and target.cpu.arch == .aarch64) { | 9281 | return true; |
| 9263 | return true; | ||
| 9264 | } | ||
| 9265 | } | 9282 | } |
| 9266 | return false; | 9283 | return false; |
| 9267 | } | 9284 | } |
src/zig_llvm.cpp+1| ... | @@ -1134,6 +1134,7 @@ void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module) { | ... | @@ -1134,6 +1134,7 @@ void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module) { |
| 1134 | } | 1134 | } |
| 1135 | 1135 | ||
| 1136 | void ZigLLVMAddModuleCodeViewFlag(LLVMModuleRef module) { | 1136 | void ZigLLVMAddModuleCodeViewFlag(LLVMModuleRef module) { |
| 1137 | unwrap(module)->addModuleFlag(Module::Warning, "Debug Info Version", DEBUG_METADATA_VERSION); | ||
| 1137 | unwrap(module)->addModuleFlag(Module::Warning, "CodeView", 1); | 1138 | unwrap(module)->addModuleFlag(Module::Warning, "CodeView", 1); |
| 1138 | } | 1139 | } |
| 1139 | 1140 |