stage1: fix @errorName null termination

This commit is contained in:
Marian Beermann 2021-12-31 18:33:43 +01:00 committed by Veikka Tuominen
parent cea6e8b2d8
commit 55709de185
2 changed files with 12 additions and 1 deletions

View File

@ -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);

View File

@ -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();