Skip to content

x86_64: increase passing test coverage on windows #24193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ pub fn build(b: *std.Build) !void {
exe.pie = pie;
exe.entitlements = entitlements;

const use_llvm = b.option(bool, "use-llvm", "Use the llvm backend");
exe.use_llvm = use_llvm;
exe.use_lld = use_llvm;

if (no_bin) {
b.getInstallStep().dependOn(&exe.step);
} else {
Expand All @@ -214,10 +218,6 @@ pub fn build(b: *std.Build) !void {

test_step.dependOn(&exe.step);

const use_llvm = b.option(bool, "use-llvm", "Use the llvm backend");
exe.use_llvm = use_llvm;
exe.use_lld = use_llvm;

const exe_options = b.addOptions();
exe.root_module.addOptions("build_options", exe_options);

Expand Down Expand Up @@ -759,7 +759,7 @@ fn addCmakeCfgOptionsToExe(
use_zig_libcxx: bool,
) !void {
const mod = exe.root_module;
const target = mod.resolved_target.?.result;
const target = &mod.resolved_target.?.result;

if (target.os.tag.isDarwin()) {
// useful for package maintainers
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler/resinator/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ fn getIncludePaths(arena: std.mem.Allocator, auto_includes_option: cli.Options.A
};
const target = std.zig.resolveTargetQueryOrFatal(target_query);
const is_native_abi = target_query.isNativeAbi();
const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, target, is_native_abi, true, null) catch {
const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, &target, is_native_abi, true, null) catch {
if (includes == .any) {
// fall back to mingw
includes = .gnu;
Expand All @@ -550,7 +550,7 @@ fn getIncludePaths(arena: std.mem.Allocator, auto_includes_option: cli.Options.A
};
const target = std.zig.resolveTargetQueryOrFatal(target_query);
const is_native_abi = target_query.isNativeAbi();
const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, target, is_native_abi, true, null) catch |err| switch (err) {
const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, &target, is_native_abi, true, null) catch |err| switch (err) {
error.OutOfMemory => |e| return e,
else => return error.MingwIncludesNotFound,
};
Expand Down
6 changes: 3 additions & 3 deletions lib/compiler_rt/common.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ else
/// Determines the symbol's visibility to other objects.
/// For WebAssembly this allows the symbol to be resolved to other modules, but will not
/// export it to the host runtime.
pub const visibility: std.builtin.SymbolVisibility = if (linkage != .internal)
.hidden
pub const visibility: std.builtin.SymbolVisibility = if (linkage == .internal or builtin.link_mode == .dynamic)
.default
else
.default;
.hidden;

pub const PreferredLoadStoreElement = element: {
if (std.simd.suggestVectorLength(u8)) |vec_size| {
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler_rt/divmodei4.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []u32, v: []u32) !void {

pub fn __divei4(q_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void {
@setRuntimeSafety(builtin.is_test);
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size]));
const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
const v: []u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
Expand All @@ -44,7 +44,7 @@ pub fn __divei4(q_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) vo

pub fn __modei4(r_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void {
@setRuntimeSafety(builtin.is_test);
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size]));
const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
const v: []u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler_rt/fixdfei.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __fixdfei(r: [*]u8, bits: usize, a: f64) callconv(.c) void {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/fixhfei.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __fixhfei(r: [*]u8, bits: usize, a: f16) callconv(.c) void {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/fixsfei.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __fixsfei(r: [*]u8, bits: usize, a: f32) callconv(.c) void {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/fixtfei.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __fixtfei(r: [*]u8, bits: usize, a: f128) callconv(.c) void {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/fixunsdfei.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __fixunsdfei(r: [*]u8, bits: usize, a: f64) callconv(.c) void {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/fixunshfei.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __fixunshfei(r: [*]u8, bits: usize, a: f16) callconv(.c) void {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/fixunssfei.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __fixunssfei(r: [*]u8, bits: usize, a: f32) callconv(.c) void {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/fixunstfei.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __fixunstfei(r: [*]u8, bits: usize, a: f128) callconv(.c) void {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/fixunsxfei.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __fixunsxfei(r: [*]u8, bits: usize, a: f80) callconv(.c) void {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/fixxfei.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __fixxfei(r: [*]u8, bits: usize, a: f80) callconv(.c) void {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/floateidf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __floateidf(a: [*]const u8, bits: usize) callconv(.c) f64 {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return floatFromBigInt(f64, .signed, @ptrCast(@alignCast(a[0..byte_size])));
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/floateihf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __floateihf(a: [*]const u8, bits: usize) callconv(.c) f16 {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return floatFromBigInt(f16, .signed, @ptrCast(@alignCast(a[0..byte_size])));
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/floateisf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __floateisf(a: [*]const u8, bits: usize) callconv(.c) f32 {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return floatFromBigInt(f32, .signed, @ptrCast(@alignCast(a[0..byte_size])));
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/floateitf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __floateitf(a: [*]const u8, bits: usize) callconv(.c) f128 {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return floatFromBigInt(f128, .signed, @ptrCast(@alignCast(a[0..byte_size])));
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/floateixf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __floateixf(a: [*]const u8, bits: usize) callconv(.c) f80 {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return floatFromBigInt(f80, .signed, @ptrCast(@alignCast(a[0..byte_size])));
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/floatuneidf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __floatuneidf(a: [*]const u8, bits: usize) callconv(.c) f64 {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return floatFromBigInt(f64, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/floatuneihf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __floatuneihf(a: [*]const u8, bits: usize) callconv(.c) f16 {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return floatFromBigInt(f16, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/floatuneisf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __floatuneisf(a: [*]const u8, bits: usize) callconv(.c) f32 {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return floatFromBigInt(f32, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/floatuneitf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __floatuneitf(a: [*]const u8, bits: usize) callconv(.c) f128 {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return floatFromBigInt(f128, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
}
2 changes: 1 addition & 1 deletion lib/compiler_rt/floatuneixf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ comptime {
}

pub fn __floatuneixf(a: [*]const u8, bits: usize) callconv(.c) f80 {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
return floatFromBigInt(f80, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
}
56 changes: 28 additions & 28 deletions lib/compiler_rt/stack_probe.zig
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,23 @@ fn win_probe_stack_only() void {
},
.x86_64 => {
asm volatile (
\\ push %%rcx
\\ push %%rax
\\ cmp $0x1000,%%rax
\\ lea 24(%%rsp),%%rcx
\\ pushq %%rcx
\\ pushq %%rax
\\ cmpq $0x1000,%%rax
\\ leaq 24(%%rsp),%%rcx
\\ jb 1f
\\ 2:
\\ sub $0x1000,%%rcx
\\ test %%rcx,(%%rcx)
\\ sub $0x1000,%%rax
\\ cmp $0x1000,%%rax
\\ subq $0x1000,%%rcx
\\ testq %%rcx,(%%rcx)
\\ subq $0x1000,%%rax
\\ cmpq $0x1000,%%rax
\\ ja 2b
\\ 1:
\\ sub %%rax,%%rcx
\\ test %%rcx,(%%rcx)
\\ pop %%rax
\\ pop %%rcx
\\ ret
\\ subq %%rax,%%rcx
\\ testq %%rcx,(%%rcx)
\\ popq %%rax
\\ popq %%rcx
\\ retq
);
},
.x86 => {
Expand Down Expand Up @@ -179,26 +179,26 @@ fn win_probe_stack_adjust_sp() void {
switch (arch) {
.x86_64 => {
asm volatile (
\\ push %%rcx
\\ cmp $0x1000,%%rax
\\ lea 16(%%rsp),%%rcx
\\ pushq %%rcx
\\ cmpq $0x1000,%%rax
\\ leaq 16(%%rsp),%%rcx
\\ jb 1f
\\ 2:
\\ sub $0x1000,%%rcx
\\ test %%rcx,(%%rcx)
\\ sub $0x1000,%%rax
\\ cmp $0x1000,%%rax
\\ subq $0x1000,%%rcx
\\ testq %%rcx,(%%rcx)
\\ subq $0x1000,%%rax
\\ cmpq $0x1000,%%rax
\\ ja 2b
\\ 1:
\\ sub %%rax,%%rcx
\\ test %%rcx,(%%rcx)
\\ subq %%rax,%%rcx
\\ testq %%rcx,(%%rcx)
\\
\\ lea 8(%%rsp),%%rax
\\ mov %%rcx,%%rsp
\\ mov -8(%%rax),%%rcx
\\ push (%%rax)
\\ sub %%rsp,%%rax
\\ ret
\\ leaq 8(%%rsp),%%rax
\\ movq %%rcx,%%rsp
\\ movq -8(%%rax),%%rcx
\\ pushq (%%rax)
\\ subq %%rsp,%%rax
\\ retq
);
},
.x86 => {
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler_rt/udivmodei4.zig
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {

pub fn __udivei4(q_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void {
@setRuntimeSafety(builtin.is_test);
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size]));
const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
const v: []const u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
Expand All @@ -123,7 +123,7 @@ pub fn __udivei4(q_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) ca

pub fn __umodei4(r_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void {
@setRuntimeSafety(builtin.is_test);
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size]));
const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
const v: []const u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
Expand Down
32 changes: 31 additions & 1 deletion lib/std/Build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,14 @@ pub fn addRunArtifact(b: *Build, exe: *Step.Compile) *Step.Run {
// It doesn't have to be native. We catch that if you actually try to run it.
// Consider that this is declarative; the run step may not be run unless a user
// option is supplied.
const run_step = Step.Run.create(b, b.fmt("run {s}", .{exe.name}));

// Avoid the common case of the step name looking like "run test test".
const step_name = if (exe.kind.isTest() and mem.eql(u8, exe.name, "test"))
b.fmt("run {s}", .{@tagName(exe.kind)})
else
b.fmt("run {s} {s}", .{ @tagName(exe.kind), exe.name });

const run_step = Step.Run.create(b, step_name);
run_step.producer = exe;
if (exe.kind == .@"test") {
if (exe.exec_cmd_args) |exec_cmd_args| {
Expand Down Expand Up @@ -2449,12 +2456,23 @@ pub const GeneratedFile = struct {
/// This value must be set in the `fn make()` of the `step` and must not be `null` afterwards.
path: ?[]const u8 = null,

/// Deprecated, see `getPath2`.
pub fn getPath(gen: GeneratedFile) []const u8 {
return gen.step.owner.pathFromCwd(gen.path orelse std.debug.panic(
"getPath() was called on a GeneratedFile that wasn't built yet. Is there a missing Step dependency on step '{s}'?",
.{gen.step.name},
));
}

pub fn getPath2(gen: GeneratedFile, src_builder: *Build, asking_step: ?*Step) []const u8 {
return gen.path orelse {
std.debug.lockStdErr();
const stderr = std.io.getStdErr();
dumpBadGetPathHelp(gen.step, stderr, src_builder, asking_step) catch {};
std.debug.unlockStdErr();
@panic("misconfigured build script");
};
}
};

// dirnameAllowEmpty is a variant of fs.path.dirname
Expand Down Expand Up @@ -2705,6 +2723,18 @@ pub const LazyPath = union(enum) {
}
}

pub fn basename(lazy_path: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 {
return fs.path.basename(switch (lazy_path) {
.src_path => |sp| sp.sub_path,
.cwd_relative => |sub_path| sub_path,
.generated => |gen| if (gen.sub_path.len > 0)
gen.sub_path
else
gen.file.getPath2(src_builder, asking_step),
.dependency => |dep| dep.sub_path,
});
}

/// Copies the internal strings.
///
/// The `b` parameter is only used for its allocator. All *Build instances
Expand Down
Loading