| author | |
| committer | |
| log | e9ac2ce1167f0f2f86d824549b8ab04d1028129c |
| tree | 4a0323bfbcd819650b1701bdcca29cb676d5be7c |
| parent | dfa55e193d04ad96c0049a48f58412ebb12c08ab |
| signature |
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.3 files changed, 12 insertions(+), 5 deletions(-)
lib/c/string.zig-5| ... | ... | @@ -4,7 +4,6 @@ const common = @import("common.zig"); |
| 4 | 4 | |
| 5 | 5 | comptime { |
| 6 | 6 | @export(&strcmp, .{ .name = "strcmp", .linkage = common.linkage, .visibility = common.visibility }); |
| 7 | @export(&strlen, .{ .name = "strlen", .linkage = common.linkage, .visibility = common.visibility }); | |
| 8 | 7 | @export(&strncmp, .{ .name = "strncmp", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 8 | @export(&strcasecmp, .{ .name = "strcasecmp", .linkage = common.linkage, .visibility = common.visibility }); |
| 10 | 9 | @export(&strncasecmp, .{ .name = "strncasecmp", .linkage = common.linkage, .visibility = common.visibility }); |
| ... | ... | @@ -103,7 +102,3 @@ test strncmp { |
| 103 | 102 | try std.testing.expect(strncmp(@ptrCast("b"), @ptrCast("a"), 1) > 0); |
| 104 | 103 | try std.testing.expect(strncmp(@ptrCast("\xff"), @ptrCast("\x02"), 1) > 0); |
| 105 | 104 | } |
| 106 | ||
| 107 | fn strlen(s: [*:0]const c_char) callconv(.c) usize { | |
| 108 | return std.mem.len(s); | |
| 109 | } |
lib/compiler_rt.zig+2| ... | ... | @@ -263,6 +263,8 @@ comptime { |
| 263 | 263 | _ = @import("compiler_rt/memcmp.zig"); |
| 264 | 264 | _ = @import("compiler_rt/bcmp.zig"); |
| 265 | 265 | _ = @import("compiler_rt/ssp.zig"); |
| 266 | ||
| 267 | _ = @import("compiler_rt/strlen.zig"); | |
| 266 | 268 | } |
| 267 | 269 | |
| 268 | 270 | // Temporarily used for uefi until https://github.com/ziglang/zig/issues/21630 is addressed. |
lib/compiler_rt/strlen.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | const std = @import("std"); | |
| 2 | const common = @import("common.zig"); | |
| 3 | ||
| 4 | comptime { | |
| 5 | @export(&strlen, .{ .name = "strlen", .linkage = common.linkage, .visibility = common.visibility }); | |
| 6 | } | |
| 7 | ||
| 8 | fn strlen(s: [*:0]const c_char) callconv(.c) usize { | |
| 9 | return std.mem.len(s); | |
| 10 | } |