Skip to content

Commit

Permalink
Merge branch 'master' into undef-checks
Browse files Browse the repository at this point in the history
  • Loading branch information
wrongnull authored Mar 9, 2025
2 parents 1bf28a5 + 539f3ef commit 54b6586
Show file tree
Hide file tree
Showing 34 changed files with 1,207 additions and 1,138 deletions.
11 changes: 4 additions & 7 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,10 @@ pub fn build(b: *std.Build) !void {
var code: u8 = undefined;
const git_describe_untrimmed = b.runAllowFail(&[_][]const u8{
"git",
"-C",
b.build_root.path orelse ".",
"describe",
"--match",
"*.*.*",
"--tags",
"--abbrev=9",
"-C", b.build_root.path orelse ".", // affects the --git-dir argument
"--git-dir", ".git", // affected by the -C argument
"describe", "--match", "*.*.*", //
"--tags", "--abbrev=9",
}, &code, .Ignore) catch {
break :v version_string;
};
Expand Down
5 changes: 3 additions & 2 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -5498,8 +5498,9 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
{#header_open|@splat#}
<pre>{#syntax#}@splat(scalar: anytype) anytype{#endsyntax#}</pre>
<p>
Produces a vector where each element is the value {#syntax#}scalar{#endsyntax#}.
The return type and thus the length of the vector is inferred.
Produces an array or vector where each element is the value
{#syntax#}scalar{#endsyntax#}. The return type and thus the length of the
vector is inferred.
</p>
{#code|test_splat_builtin.zig#}

Expand Down
6 changes: 6 additions & 0 deletions doc/langref/test_splat_builtin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ test "vector @splat" {
try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
}

test "array @splat" {
const scalar: u32 = 5;
const result: [4]u32 = @splat(scalar);
try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
}

// test
6 changes: 3 additions & 3 deletions lib/compiler/aro/aro/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub fn unnamedFieldAffectsAlignment(target: std.Target) bool {
},
.armeb => {
if (std.Target.arm.featureSetHas(target.cpu.features, .has_v7)) {
if (std.Target.Abi.default(target.cpu.arch, target.os) == .eabi) return true;
if (std.Target.Abi.default(target.cpu.arch, target.os.tag) == .eabi) return true;
}
},
.arm => return true,
Expand Down Expand Up @@ -716,7 +716,7 @@ test "alignment functions - smoke test" {
const x86 = std.Target.Cpu.Arch.x86_64;
target.os = std.Target.Os.Tag.defaultVersionRange(.linux, x86, .none);
target.cpu = std.Target.Cpu.baseline(x86, target.os);
target.abi = std.Target.Abi.default(x86, target.os);
target.abi = std.Target.Abi.default(x86, target.os.tag);

try std.testing.expect(isTlsSupported(target));
try std.testing.expect(!ignoreNonZeroSizedBitfieldTypeAlignment(target));
Expand All @@ -729,7 +729,7 @@ test "alignment functions - smoke test" {
const arm = std.Target.Cpu.Arch.arm;
target.os = std.Target.Os.Tag.defaultVersionRange(.ios, arm, .none);
target.cpu = std.Target.Cpu.baseline(arm, target.os);
target.abi = std.Target.Abi.default(arm, target.os);
target.abi = std.Target.Abi.default(arm, target.os.tag);

try std.testing.expect(!isTlsSupported(target));
try std.testing.expect(ignoreNonZeroSizedBitfieldTypeAlignment(target));
Expand Down
6 changes: 4 additions & 2 deletions lib/compiler_rt/int_from_float.zig
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ pub inline fn bigIntFromFloat(comptime signedness: std.builtin.Signedness, resul
} });

const parts = math.frexp(a);
const exponent = @max(parts.exponent - significand_bits, 0);
const significand_bits_adjusted_to_handle_smin = @as(i32, significand_bits) +
@intFromBool(signedness == .signed and parts.exponent == 32 * result.len);
const exponent = @max(parts.exponent - significand_bits_adjusted_to_handle_smin, 0);
const int: I = @intFromFloat(switch (exponent) {
0 => a,
else => math.ldexp(parts.significand, significand_bits),
else => math.ldexp(parts.significand, significand_bits_adjusted_to_handle_smin),
});
switch (signedness) {
.signed => {
Expand Down
40 changes: 40 additions & 0 deletions lib/compiler_rt/int_from_float_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const __fixdfdi = @import("fixdfdi.zig").__fixdfdi;
const __fixunsdfdi = @import("fixunsdfdi.zig").__fixunsdfdi;
const __fixdfti = @import("fixdfti.zig").__fixdfti;
const __fixunsdfti = @import("fixunsdfti.zig").__fixunsdfti;
const __fixdfei = @import("fixdfei.zig").__fixdfei;
const __fixunsdfei = @import("fixunsdfei.zig").__fixunsdfei;

// Conversion from f128
const __fixtfsi = @import("fixtfsi.zig").__fixtfsi;
Expand Down Expand Up @@ -681,6 +683,44 @@ test "fixunsdfti" {
try test__fixunsdfti(-0x1.FFFFFFFFFFFFEp+62, 0);
}

fn test_fixdfei(comptime T: type, expected: T, a: f64) !void {
const int = @typeInfo(T).int;
var expected_buf: [@divExact(int.bits, 32)]u32 = undefined;
std.mem.writeInt(T, std.mem.asBytes(&expected_buf), expected, endian);
var actual_buf: [@divExact(int.bits, 32)]u32 = undefined;
_ = switch (int.signedness) {
.signed => __fixdfei,
.unsigned => __fixunsdfei,
}(&actual_buf, int.bits, a);
try testing.expect(std.mem.eql(u32, &expected_buf, &actual_buf));
}

test "fixdfei" {
try test_fixdfei(i256, -1 << 255, -0x1p255);
try test_fixdfei(i256, -1 << 127, -0x1p127);
try test_fixdfei(i256, -1 << 100, -0x1p100);
try test_fixdfei(i256, -1 << 50, -0x1p50);
try test_fixdfei(i256, -1 << 1, -0x1p1);
try test_fixdfei(i256, -1 << 0, -0x1p0);
try test_fixdfei(i256, 0, 0);
try test_fixdfei(i256, 1 << 0, 0x1p0);
try test_fixdfei(i256, 1 << 1, 0x1p1);
try test_fixdfei(i256, 1 << 50, 0x1p50);
try test_fixdfei(i256, 1 << 100, 0x1p100);
try test_fixdfei(i256, 1 << 127, 0x1p127);
try test_fixdfei(i256, 1 << 254, 0x1p254);
}

test "fixundfei" {
try test_fixdfei(u256, 0, 0);
try test_fixdfei(u256, 1 << 0, 0x1p0);
try test_fixdfei(u256, 1 << 1, 0x1p1);
try test_fixdfei(u256, 1 << 50, 0x1p50);
try test_fixdfei(u256, 1 << 100, 0x1p100);
try test_fixdfei(u256, 1 << 127, 0x1p127);
try test_fixdfei(u256, 1 << 255, 0x1p255);
}

fn test__fixtfsi(a: f128, expected: i32) !void {
const x = __fixtfsi(a);
try testing.expect(x == expected);
Expand Down
20 changes: 0 additions & 20 deletions lib/std/Build/Cache.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1254,11 +1254,6 @@ fn testGetCurrentFileTimestamp(dir: fs.Dir) !i128 {
}

test "cache file and then recall it" {
if (builtin.os.tag == .wasi) {
// https://github.com/ziglang/zig/issues/5437
return error.SkipZigTest;
}

var tmp = testing.tmpDir(.{});
defer tmp.cleanup();

Expand Down Expand Up @@ -1320,11 +1315,6 @@ test "cache file and then recall it" {
}

test "check that changing a file makes cache fail" {
if (builtin.os.tag == .wasi) {
// https://github.com/ziglang/zig/issues/5437
return error.SkipZigTest;
}

var tmp = testing.tmpDir(.{});
defer tmp.cleanup();

Expand Down Expand Up @@ -1394,11 +1384,6 @@ test "check that changing a file makes cache fail" {
}

test "no file inputs" {
if (builtin.os.tag == .wasi) {
// https://github.com/ziglang/zig/issues/5437
return error.SkipZigTest;
}

var tmp = testing.tmpDir(.{});
defer tmp.cleanup();

Expand Down Expand Up @@ -1442,11 +1427,6 @@ test "no file inputs" {
}

test "Manifest with files added after initial hash work" {
if (builtin.os.tag == .wasi) {
// https://github.com/ziglang/zig/issues/5437
return error.SkipZigTest;
}

var tmp = testing.tmpDir(.{});
defer tmp.cleanup();

Expand Down
6 changes: 3 additions & 3 deletions lib/std/Build/Step/InstallArtifact.zig
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
const src_dir_path = dir.source.getPath3(b, step);
const full_h_prefix = b.getInstallPath(h_dir, dir.dest_rel_path);

var src_dir = src_dir_path.root_dir.handle.openDir(src_dir_path.sub_path, .{ .iterate = true }) catch |err| {
return step.fail("unable to open source directory '{s}': {s}", .{
src_dir_path.sub_path, @errorName(err),
var src_dir = src_dir_path.root_dir.handle.openDir(src_dir_path.subPathOrDot(), .{ .iterate = true }) catch |err| {
return step.fail("unable to open source directory '{}': {s}", .{
src_dir_path, @errorName(err),
});
};
defer src_dir.close();
Expand Down
4 changes: 2 additions & 2 deletions lib/std/Target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,8 @@ pub const Abi = enum {
// - raygeneration
// - vertex

pub fn default(arch: Cpu.Arch, os: Os) Abi {
return switch (os.tag) {
pub fn default(arch: Cpu.Arch, os_tag: Os.Tag) Abi {
return switch (os_tag) {
.freestanding, .other => switch (arch) {
// Soft float is usually a sane default for freestanding.
.arm,
Expand Down
2 changes: 1 addition & 1 deletion lib/std/Target/Query.zig
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn fromTarget(target: Target) Query {
.os_version_min = undefined,
.os_version_max = undefined,
.abi = target.abi,
.glibc_version = target.os.versionRange().gnuLibCVersion(),
.glibc_version = if (target.abi.isGnu()) target.os.versionRange().gnuLibCVersion() else null,
.android_api_level = if (target.abi.isAndroid()) target.os.version_range.linux.android else null,
};
result.updateOsVersionRange(target.os);
Expand Down
Loading

0 comments on commit 54b6586

Please sign in to comment.