mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
compiler-rt: move strlen from libzigc to here
LLVM 21 has started recognizing strlen-like idioms and optimizing them to strlen calls, so we need this function provided in compiler-rt for libc-less compilations.
This commit is contained in:
parent
dfa55e193d
commit
e9ac2ce116
@ -4,7 +4,6 @@ const common = @import("common.zig");
|
|||||||
|
|
||||||
comptime {
|
comptime {
|
||||||
@export(&strcmp, .{ .name = "strcmp", .linkage = common.linkage, .visibility = common.visibility });
|
@export(&strcmp, .{ .name = "strcmp", .linkage = common.linkage, .visibility = common.visibility });
|
||||||
@export(&strlen, .{ .name = "strlen", .linkage = common.linkage, .visibility = common.visibility });
|
|
||||||
@export(&strncmp, .{ .name = "strncmp", .linkage = common.linkage, .visibility = common.visibility });
|
@export(&strncmp, .{ .name = "strncmp", .linkage = common.linkage, .visibility = common.visibility });
|
||||||
@export(&strcasecmp, .{ .name = "strcasecmp", .linkage = common.linkage, .visibility = common.visibility });
|
@export(&strcasecmp, .{ .name = "strcasecmp", .linkage = common.linkage, .visibility = common.visibility });
|
||||||
@export(&strncasecmp, .{ .name = "strncasecmp", .linkage = common.linkage, .visibility = common.visibility });
|
@export(&strncasecmp, .{ .name = "strncasecmp", .linkage = common.linkage, .visibility = common.visibility });
|
||||||
@ -103,7 +102,3 @@ test strncmp {
|
|||||||
try std.testing.expect(strncmp(@ptrCast("b"), @ptrCast("a"), 1) > 0);
|
try std.testing.expect(strncmp(@ptrCast("b"), @ptrCast("a"), 1) > 0);
|
||||||
try std.testing.expect(strncmp(@ptrCast("\xff"), @ptrCast("\x02"), 1) > 0);
|
try std.testing.expect(strncmp(@ptrCast("\xff"), @ptrCast("\x02"), 1) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn strlen(s: [*:0]const c_char) callconv(.c) usize {
|
|
||||||
return std.mem.len(s);
|
|
||||||
}
|
|
||||||
|
|||||||
@ -263,6 +263,8 @@ comptime {
|
|||||||
_ = @import("compiler_rt/memcmp.zig");
|
_ = @import("compiler_rt/memcmp.zig");
|
||||||
_ = @import("compiler_rt/bcmp.zig");
|
_ = @import("compiler_rt/bcmp.zig");
|
||||||
_ = @import("compiler_rt/ssp.zig");
|
_ = @import("compiler_rt/ssp.zig");
|
||||||
|
|
||||||
|
_ = @import("compiler_rt/strlen.zig");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Temporarily used for uefi until https://github.com/ziglang/zig/issues/21630 is addressed.
|
// Temporarily used for uefi until https://github.com/ziglang/zig/issues/21630 is addressed.
|
||||||
|
|||||||
10
lib/compiler_rt/strlen.zig
Normal file
10
lib/compiler_rt/strlen.zig
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const common = @import("common.zig");
|
||||||
|
|
||||||
|
comptime {
|
||||||
|
@export(&strlen, .{ .name = "strlen", .linkage = common.linkage, .visibility = common.visibility });
|
||||||
|
}
|
||||||
|
|
||||||
|
fn strlen(s: [*:0]const c_char) callconv(.c) usize {
|
||||||
|
return std.mem.len(s);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user