authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-01 19:51:14-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-01 19:51:14-07:00
log665737d845a5fc5a9182541cbe47643ee6d9f3f6
tree34ccecf40166f5d6fea3cbd24a9b9fefc4d04441
parentf23b15b4d59afa9d12d46138b81b29d59b5e00d4
parentedf785db0f30842b958f540a3aaf7205b8b82493

Merge remote-tracking branch 'origin/master' into wrangle-writer-buffering


17 files changed, 142 insertions(+), 20 deletions(-)

doc/langref/runtime_shrExact_overflow.zig+3
......@@ -1,3 +1,4 @@
1const builtin = @import("builtin");
12const std = @import("std");
23
34pub fn main() void {
......@@ -5,6 +6,8 @@ pub fn main() void {
56 _ = &x;
67 const y = @shrExact(x, 2);
78 std.debug.print("value: {}\n", .{y});
9
10 if (builtin.cpu.arch.isRISCV() and builtin.zig_backend == .stage2_llvm) @panic("https://github.com/ziglang/zig/issues/24304");
811}
912
1013// exe=fail
lib/libunwind/src/UnwindCursor.hpp+1-1
......@@ -150,7 +150,7 @@ bool DwarfFDECache<A>::_registeredForDyldUnloads = false;
150150#endif
151151
152152template <typename A>
153typename A::pint_t DwarfFDECache<A>::findFDE(pint_t mh, pint_t pc) {
153typename DwarfFDECache<A>::pint_t DwarfFDECache<A>::findFDE(pint_t mh, pint_t pc) {
154154 pint_t result = 0;
155155 _LIBUNWIND_LOG_IF_FALSE(_lock.lock_shared());
156156 for (entry *p = _buffer; p < _bufferUsed; ++p) {
lib/std/Build/Step/CheckObject.zig+1-1
......@@ -2208,7 +2208,7 @@ const ElfDumper = struct {
22082208 try bw.print(" {s}", .{sym_bind});
22092209 }
22102210
2211 const sym_vis = @as(elf.STV, @enumFromInt(sym.st_other));
2211 const sym_vis = @as(elf.STV, @enumFromInt(@as(u2, @truncate(sym.st_other))));
22122212 try bw.print(" {s}", .{@tagName(sym_vis)});
22132213
22142214 const sym_name = switch (sym.st_type()) {
lib/std/bit_set.zig+1
......@@ -1699,6 +1699,7 @@ fn testStaticBitSet(comptime Set: type) !void {
16991699
17001700test IntegerBitSet {
17011701 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
1702 if (comptime builtin.cpu.has(.riscv, .v) and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/24300
17021703
17031704 try testStaticBitSet(IntegerBitSet(0));
17041705 try testStaticBitSet(IntegerBitSet(1));
lib/std/crypto/salsa20.zig+6
......@@ -557,6 +557,8 @@ pub const SealedBox = struct {
557557const htest = @import("test.zig");
558558
559559test "(x)salsa20" {
560 if (builtin.cpu.has(.riscv, .v) and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/24299
561
560562 const key = [_]u8{0x69} ** 32;
561563 const nonce = [_]u8{0x42} ** 8;
562564 const msg = [_]u8{0} ** 20;
......@@ -600,6 +602,8 @@ test "xsalsa20poly1305 secretbox" {
600602}
601603
602604test "xsalsa20poly1305 box" {
605 if (builtin.cpu.has(.riscv, .v) and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/24299
606
603607 var msg: [100]u8 = undefined;
604608 var msg2: [msg.len]u8 = undefined;
605609 var nonce: [Box.nonce_length]u8 = undefined;
......@@ -614,6 +618,8 @@ test "xsalsa20poly1305 box" {
614618}
615619
616620test "xsalsa20poly1305 sealedbox" {
621 if (builtin.cpu.has(.riscv, .v) and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/24299
622
617623 var msg: [100]u8 = undefined;
618624 var msg2: [msg.len]u8 = undefined;
619625 var boxed: [msg.len + SealedBox.seal_length]u8 = undefined;
lib/std/os/linux/riscv32.zig+36-2
......@@ -7,6 +7,8 @@ const SYS = linux.SYS;
77const uid_t = std.os.linux.uid_t;
88const gid_t = std.os.linux.gid_t;
99const pid_t = std.os.linux.pid_t;
10const stack_t = linux.stack_t;
11const sigset_t = linux.sigset_t;
1012const sockaddr = linux.sockaddr;
1113const socklen_t = linux.socklen_t;
1214const timespec = std.os.linux.timespec;
......@@ -237,8 +239,40 @@ pub const VDSO = struct {
237239 pub const CGT_VER = "LINUX_4.15";
238240};
239241
240/// TODO
241pub const ucontext_t = void;
242pub const f_ext_state = extern struct {
243 f: [32]f32,
244 fcsr: u32,
245};
246
247pub const d_ext_state = extern struct {
248 f: [32]f64,
249 fcsr: u32,
250};
251
252pub const q_ext_state = extern struct {
253 f: [32]f128,
254 fcsr: u32,
255 _reserved: [3]u32,
256};
257
258pub const fpstate = extern union {
259 f: f_ext_state,
260 d: d_ext_state,
261 q: q_ext_state,
262};
263
264pub const mcontext_t = extern struct {
265 gregs: [32]u32,
266 fpregs: fpstate,
267};
268
269pub const ucontext_t = extern struct {
270 flags: c_ulong,
271 link: ?*ucontext_t,
272 stack: stack_t,
273 sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask
274 mcontext: mcontext_t,
275};
242276
243277/// TODO
244278pub const getcontext = {};
lib/std/os/linux/riscv64.zig+36-2
......@@ -7,6 +7,8 @@ const SYS = linux.SYS;
77const uid_t = std.os.linux.uid_t;
88const gid_t = std.os.linux.gid_t;
99const pid_t = std.os.linux.pid_t;
10const stack_t = linux.stack_t;
11const sigset_t = linux.sigset_t;
1012const sockaddr = linux.sockaddr;
1113const socklen_t = linux.socklen_t;
1214const timespec = std.os.linux.timespec;
......@@ -237,8 +239,40 @@ pub const VDSO = struct {
237239 pub const CGT_VER = "LINUX_4.15";
238240};
239241
240/// TODO
241pub const ucontext_t = void;
242pub const f_ext_state = extern struct {
243 f: [32]f32,
244 fcsr: u32,
245};
246
247pub const d_ext_state = extern struct {
248 f: [32]f64,
249 fcsr: u32,
250};
251
252pub const q_ext_state = extern struct {
253 f: [32]f128,
254 fcsr: u32,
255 _reserved: [3]u32,
256};
257
258pub const fpstate = extern union {
259 f: f_ext_state,
260 d: d_ext_state,
261 q: q_ext_state,
262};
263
264pub const mcontext_t = extern struct {
265 gregs: [32]u64,
266 fpregs: fpstate,
267};
268
269pub const ucontext_t = extern struct {
270 flags: c_ulong,
271 link: ?*ucontext_t,
272 stack: stack_t,
273 sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask
274 mcontext: mcontext_t,
275};
242276
243277/// TODO
244278pub const getcontext = {};
lib/std/simd.zig+2
......@@ -9,6 +9,8 @@ const std = @import("std");
99const builtin = @import("builtin");
1010
1111pub fn suggestVectorLengthForCpu(comptime T: type, comptime cpu: std.Target.Cpu) ?comptime_int {
12 @setEvalBranchQuota(2_000);
13
1214 // This is guesswork, if you have better suggestions can add it or edit the current here
1315 const element_bit_size = @max(8, std.math.ceilPowerOfTwo(u16, @bitSizeOf(T)) catch unreachable);
1416 const vector_bit_size: u16 = blk: {
lib/std/zig/system/linux.zig+2
......@@ -76,9 +76,11 @@ const RiscvCpuinfoImpl = struct {
7676
7777 const cpu_names = .{
7878 .{ "sifive,u54", &Target.riscv.cpu.sifive_u54 },
79 .{ "sifive,u54-mc", &Target.riscv.cpu.sifive_u54 },
7980 .{ "sifive,u7", &Target.riscv.cpu.sifive_7_series },
8081 .{ "sifive,u74", &Target.riscv.cpu.sifive_u74 },
8182 .{ "sifive,u74-mc", &Target.riscv.cpu.sifive_u74 },
83 .{ "spacemit,x60", &Target.riscv.cpu.spacemit_x60 },
8284 };
8385
8486 fn line_hook(self: *RiscvCpuinfoImpl, key: []const u8, value: []const u8) !bool {
src/codegen/llvm.zig+7-4
......@@ -1074,6 +1074,9 @@ pub const Object = struct {
10741074 .full => .FullPreLink,
10751075 },
10761076 .allow_fast_isel = true,
1077 // LLVM's RISC-V backend for some reason enables the machine outliner by default even
1078 // though it's clearly not ready and produces multiple miscompilations in our std tests.
1079 .allow_machine_outliner = !comp.root_mod.resolved_target.result.cpu.arch.isRISCV(),
10771080 .asm_filename = null,
10781081 .bin_filename = options.bin_path,
10791082 .llvm_ir_filename = options.post_ir_path,
......@@ -6837,8 +6840,8 @@ pub const FuncGen = struct {
68376840
68386841 self.maybeMarkAllowZeroAccess(slice_ty.ptrInfo(zcu));
68396842
6840 const elem_alignment = elem_ty.abiAlignment(zcu).toLlvm();
6841 return self.loadByRef(ptr, elem_ty, elem_alignment, if (slice_ty.isVolatilePtr(zcu)) .@"volatile" else .normal);
6843 const slice_align = (slice_ty.ptrAlignment(zcu).min(elem_ty.abiAlignment(zcu))).toLlvm();
6844 return self.loadByRef(ptr, elem_ty, slice_align, if (slice_ty.isVolatilePtr(zcu)) .@"volatile" else .normal);
68426845 }
68436846
68446847 self.maybeMarkAllowZeroAccess(slice_ty.ptrInfo(zcu));
......@@ -6915,8 +6918,8 @@ pub const FuncGen = struct {
69156918
69166919 self.maybeMarkAllowZeroAccess(ptr_ty.ptrInfo(zcu));
69176920
6918 const elem_alignment = elem_ty.abiAlignment(zcu).toLlvm();
6919 return self.loadByRef(ptr, elem_ty, elem_alignment, if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal);
6921 const ptr_align = (ptr_ty.ptrAlignment(zcu).min(elem_ty.abiAlignment(zcu))).toLlvm();
6922 return self.loadByRef(ptr, elem_ty, ptr_align, if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal);
69206923 }
69216924
69226925 self.maybeMarkAllowZeroAccess(ptr_ty.ptrInfo(zcu));
src/codegen/llvm/bindings.zig+1
......@@ -92,6 +92,7 @@ pub const TargetMachine = opaque {
9292 sancov: bool,
9393 lto: LtoPhase,
9494 allow_fast_isel: bool,
95 allow_machine_outliner: bool,
9596 asm_filename: ?[*:0]const u8,
9697 bin_filename: ?[*:0]const u8,
9798 llvm_ir_filename: ?[*:0]const u8,
src/zig_llvm.cpp+10-6
......@@ -260,6 +260,16 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi
260260
261261 TargetMachine &target_machine = *reinterpret_cast<TargetMachine*>(targ_machine_ref);
262262
263 if (options->allow_fast_isel) {
264 target_machine.setO0WantsFastISel(true);
265 } else {
266 target_machine.setFastISel(false);
267 }
268
269 if (!options->allow_machine_outliner) {
270 target_machine.setMachineOutliner(false);
271 }
272
263273 Module &llvm_module = *unwrap(module_ref);
264274
265275 // Pipeline configurations
......@@ -385,12 +395,6 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi
385395 }
386396 }
387397
388 if (options->allow_fast_isel) {
389 target_machine.setO0WantsFastISel(true);
390 } else {
391 target_machine.setFastISel(false);
392 }
393
394398 // Optimization phase
395399 module_pm.run(llvm_module, module_am);
396400
src/zig_llvm.h+1
......@@ -71,6 +71,7 @@ struct ZigLLVMEmitOptions {
7171 bool sancov;
7272 ZigLLVMThinOrFullLTOPhase lto;
7373 bool allow_fast_isel;
74 bool allow_machine_outliner;
7475 const char *asm_filename;
7576 const char *bin_filename;
7677 const char *llvm_ir_filename;
test/behavior/vector.zig+1
......@@ -560,6 +560,7 @@ test "vector division operators" {
560560 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
561561 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
562562 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
563 if (comptime builtin.cpu.has(.riscv, .v) and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/24301
563564
564565 const S = struct {
565566 fn doTheTestDiv(comptime T: type, x: @Vector(4, T), y: @Vector(4, T)) !void {
test/link/glibc_compat/build.zig+21-4
......@@ -33,7 +33,7 @@ pub fn build(b: *std.Build) void {
3333 }
3434
3535 // Build & run a C test case against a sampling of supported glibc versions
36 for ([_][]const u8{
36 versions: for ([_][]const u8{
3737 // "native-linux-gnu.2.0", // fails with a pile of missing symbols.
3838 "native-linux-gnu.2.2.5",
3939 "native-linux-gnu.2.4",
......@@ -52,9 +52,14 @@ pub fn build(b: *std.Build) void {
5252 const glibc_ver = target.result.os.version_range.linux.glibc;
5353
5454 // only build test if glibc version supports the architecture
55 if (target.result.cpu.arch.isAARCH64()) {
56 if (glibc_ver.order(.{ .major = 2, .minor = 17, .patch = 0 }) == .lt) {
55 for (std.zig.target.available_libcs) |libc| {
56 if (libc.arch != target.result.cpu.arch or
57 libc.os != target.result.os.tag or
58 libc.abi != target.result.abi)
5759 continue;
60
61 if (libc.glibc_min) |min| {
62 if (glibc_ver.order(min) == .lt) continue :versions;
5863 }
5964 }
6065
......@@ -147,7 +152,7 @@ pub fn build(b: *std.Build) void {
147152 }
148153
149154 // Build & run a Zig test case against a sampling of supported glibc versions
150 for ([_][]const u8{
155 versions: for ([_][]const u8{
151156 "native-linux-gnu.2.17", // Currently oldest supported, see #17769
152157 "native-linux-gnu.2.23",
153158 "native-linux-gnu.2.28",
......@@ -161,6 +166,18 @@ pub fn build(b: *std.Build) void {
161166
162167 const glibc_ver = target.result.os.version_range.linux.glibc;
163168
169 // only build test if glibc version supports the architecture
170 for (std.zig.target.available_libcs) |libc| {
171 if (libc.arch != target.result.cpu.arch or
172 libc.os != target.result.os.tag or
173 libc.abi != target.result.abi)
174 continue;
175
176 if (libc.glibc_min) |min| {
177 if (glibc_ver.order(min) == .lt) continue :versions;
178 }
179 }
180
164181 const exe = b.addExecutable(.{
165182 .name = t,
166183 .root_module = b.createModule(.{
test/standalone/coff_dwarf/build.zig+8
......@@ -3,6 +3,14 @@ const builtin = @import("builtin");
33
44/// This tests the path where DWARF information is embedded in a COFF binary
55pub fn build(b: *std.Build) void {
6 switch (builtin.cpu.arch) {
7 .aarch64,
8 .x86,
9 .x86_64,
10 => {},
11 else => return,
12 }
13
614 const test_step = b.step("test", "Test it");
715 b.default_step = test_step;
816
test/standalone/stack_iterator/build.zig+5
......@@ -8,6 +8,11 @@ pub fn build(b: *std.Build) void {
88 const target = b.standardTargetOptions(.{});
99 const optimize = b.standardOptimizeOption(.{});
1010
11 if (target.result.cpu.arch.isRISCV() and target.result.os.tag == .linux) {
12 // https://github.com/ziglang/zig/issues/24310
13 return;
14 }
15
1116 // Unwinding with a frame pointer
1217 //
1318 // getcontext version: zig std