commit 54706dd2294d998c6c6ad91c80a23a3471677c43 (tree)
parent ecf7dfcd3a3e575ee525487687a0b7607a6a7481
Author: Jakub Konka <kubkon@jakubkonka.com>
Date: Thu, 3 Dec 2020 21:07:01 +0100
Allow idx 0 err to be put into error_name_table
This way, in the very situation where a function has a return type
an error union such as `anyerror!void` but doesn't have any erroneous
paths, calling `@errorName` on the unpacked error (which will never
be triggered) will not trip up the static analyzer.
Diffstat:
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp
@@ -5178,11 +5178,7 @@ static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutableGen *executable, IrIns
static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutableGen *executable, IrInstGenErrName *instruction) {
assert(g->generate_error_name_table);
-
- if (g->errors_by_index.length == 1) {
- LLVMBuildUnreachable(g->builder);
- return nullptr;
- }
+ assert(g->errors_by_index.length > 0);
LLVMValueRef err_val = ir_llvm_value(g, instruction->value);
if (ir_want_runtime_safety(g, &instruction->base)) {
@@ -7890,7 +7886,7 @@ static void render_const_val_global(CodeGen *g, ZigValue *const_val, const char
}
static void generate_error_name_table(CodeGen *g) {
- if (g->err_name_table != nullptr || !g->generate_error_name_table || g->errors_by_index.length == 1) {
+ if (g->err_name_table != nullptr || !g->generate_error_name_table) {
return;
}