mirror of
https://github.com/ziglang/zig.git
synced 2024-12-02 18:12:34 +00:00
stage1: fix @errorName null termination
This commit is contained in:
parent
cea6e8b2d8
commit
55709de185
@ -8193,7 +8193,7 @@ static void generate_error_name_table(CodeGen *g) {
|
||||
|
||||
g->largest_err_name_len = max(g->largest_err_name_len, buf_len(name));
|
||||
|
||||
LLVMValueRef str_init = LLVMConstString(buf_ptr(name), (unsigned)buf_len(name), true);
|
||||
LLVMValueRef str_init = LLVMConstString(buf_ptr(name), (unsigned)buf_len(name), false);
|
||||
LLVMValueRef str_global = LLVMAddGlobal(g->module, LLVMTypeOf(str_init), "");
|
||||
LLVMSetInitializer(str_global, str_init);
|
||||
LLVMSetLinkage(str_global, LLVMPrivateLinkage);
|
||||
|
@ -14,6 +14,17 @@ test "@errorName" {
|
||||
try expect(mem.eql(u8, @errorName(gimmeItBroke()), "ItBroke"));
|
||||
}
|
||||
|
||||
test "@errorName sentinel length matches slice length" {
|
||||
const name = testBuiltinErrorName(error.FooBar);
|
||||
const length: usize = 6;
|
||||
try expectEqual(length, std.mem.indexOfSentinel(u8, 0, name.ptr));
|
||||
try expectEqual(length, name.len);
|
||||
}
|
||||
|
||||
pub fn testBuiltinErrorName(err: anyerror) [:0]const u8 {
|
||||
return @errorName(err);
|
||||
}
|
||||
|
||||
test "error union type " {
|
||||
try testErrorUnionType();
|
||||
comptime try testErrorUnionType();
|
||||
|
Loading…
Reference in New Issue
Block a user