Update panic emit.

This commit is contained in:
Christoffer Lerno
2023-11-13 19:49:25 +01:00
parent 1dde6092e5
commit 9345e4270a
6 changed files with 16 additions and 20 deletions

View File

@@ -4418,10 +4418,9 @@ static inline void llvm_emit_force_unwrap_expr(GenContext *c, BEValue *be_value,
llvm_emit_any_from_value(c, &fault_arg, type_anyfault);
vec_add(varargs, fault_arg);
llvm_emit_panic(c, "Force unwrap failed!", loc, "Unexpected fault '%s' was unwrapped!", varargs);
llvm_emit_unreachable(c);
}
llvm_emit_block(c, no_err_block);
EMIT_LOC(c, expr);
}
@@ -5963,8 +5962,8 @@ static void llvm_emit_call_expr(GenContext *c, BEValue *result_value, Expr *expr
scratch_buffer_clear();
scratch_buffer_printf("No method '%s' could be found on target", dyn_fn->name);
llvm_emit_panic(c, scratch_buffer_to_string(), expr->span, NULL, NULL);
llvm_emit_unreachable(c);
llvm_emit_block(c, match);
EMIT_LOC(c, expr);
values[0] = result;
}
@@ -6469,8 +6468,8 @@ static inline void llvm_emit_typeid_info(GenContext *c, BEValue *value, Expr *ex
llvm_emit_block(c, next);
}
llvm_emit_panic(c, "Attempted to access 'inner' on non composite type", expr->span, NULL, NULL);
llvm_emit_unreachable(c);
llvm_emit_block(c, exit);
EMIT_LOC(c, expr);
}
{
LLVMValueRef val = llvm_emit_struct_gep_raw(c, ref, c->introspect_type, INTROSPECT_INDEX_INNER, align, &alignment);
@@ -6498,8 +6497,8 @@ static inline void llvm_emit_typeid_info(GenContext *c, BEValue *value, Expr *ex
llvm_emit_block(c, next);
}
llvm_emit_panic(c, "Attempted to access 'names' on non enum/fault type.", expr->span, NULL, NULL);
llvm_emit_unreachable(c);
llvm_emit_block(c, exit);
EMIT_LOC(c, expr);
}
{
LLVMValueRef len = llvm_emit_struct_gep_raw(c, ref, c->introspect_type, INTROSPECT_INDEX_LEN, align, &alignment);
@@ -6531,8 +6530,8 @@ static inline void llvm_emit_typeid_info(GenContext *c, BEValue *value, Expr *ex
llvm_emit_block(c, next);
}
llvm_emit_panic(c, "Attempted to access 'len' on non array type", expr->span, NULL, NULL);
llvm_emit_unreachable(c);
llvm_emit_block(c, exit);
EMIT_LOC(c, expr);
}
{
LLVMValueRef val = llvm_emit_struct_gep_raw(c, ref, c->introspect_type, INTROSPECT_INDEX_LEN, align, &alignment);

View File

@@ -72,7 +72,6 @@ typedef struct
unsigned runtime_version : 8;
bool enable_stacktrace : 1;
bool emulated_stacktrace : 1;
bool x : 1;
LLVMDIBuilderRef builder;
DebugFile *debug_files;
DebugFile file;
@@ -550,7 +549,8 @@ void llvm_emit_update_stack_row(GenContext *c, uint32_t row);
void llvm_emit_pop_stacktrace(GenContext *c, Stacktrace *slot);
void llvm_emit_push_emulated_stacktrace(GenContext *c, Decl *decl, const char *function_name, StacktraceType type);
#define EMIT_LOC(c, x) do { if (c->debug.builder) llvm_emit_debug_location(c, x->span); } while (0);
#define EMIT_LOC(c, x) do { if (c->debug.builder) llvm_emit_debug_location(c, x->span); } while (0)
#define EMIT_SPAN(c, x) do { if (c->debug.builder) llvm_emit_debug_location(c, x); } while (0)
LLVMAtomicOrdering llvm_atomic_ordering(Atomicity atomicity);

View File

@@ -169,7 +169,6 @@ void gencontext_begin_module(GenContext *c)
LLVMStructSetBody(c->debug.stack_type, types, 5, false);
c->debug.current_stack_ptr = NULL;
c->debug.enable_stacktrace = true;
c->debug.x = false;
c->debug.emulated_stacktrace = !os_supports_stacktrace(platform_target.os);
}
}

View File

@@ -470,9 +470,7 @@ void llvm_emit_for_stmt(GenContext *c, Ast *ast)
SourceSpan loc = ast->span;
llvm_emit_panic(c, "Infinite loop found", loc, NULL, NULL);
llvm_emit_unreachable(c);
LLVMBasicBlockRef block = llvm_basic_block_new(c, "unreachable_block");
llvm_emit_block(c, block);
llvm_emit_block(c, llvm_basic_block_new(c, "unreachable_block"));
return;
}
return;
@@ -1000,7 +998,6 @@ static inline void llvm_emit_assert_stmt(GenContext *c, Ast *ast)
{
ExprId exprid = ast->assert_stmt.expr;
Expr *assert_expr = exprptr(exprid);
if (safe_mode_enabled())
{
BEValue value;
@@ -1036,8 +1033,9 @@ static inline void llvm_emit_assert_stmt(GenContext *c, Ast *ast)
}
}
llvm_emit_panic(c, error, loc, fmt, values);
llvm_emit_unreachable(c);
llvm_emit_block(c, on_ok);
EMIT_LOC(c, ast);
return;
}
llvm_emit_assume(c, exprptr(ast->assert_stmt.expr));
}
@@ -1312,6 +1310,7 @@ void llvm_emit_panic(GenContext *c, const char *message, SourceSpan loc, const c
if (!panic_var)
{
llvm_emit_call_intrinsic(c, intrinsic_id.trap, NULL, 0, NULL, 0);
llvm_emit_unreachable(c);
return;
}
@@ -1368,6 +1367,7 @@ void llvm_emit_panic(GenContext *c, const char *message, SourceSpan loc, const c
if (c->debug.builder) llvm_emit_debug_location(c, loc);
llvm_emit_raw_call(c, &res, prototype, llvm_func_type(c, prototype), llvm_get_ref(c, panicf), actual_args,
count, 0, NULL, false, NULL);
llvm_emit_unreachable(c);
return;
}
@@ -1379,6 +1379,7 @@ void llvm_emit_panic(GenContext *c, const char *message, SourceSpan loc, const c
if (c->debug.builder) llvm_emit_debug_location(c, loc);
llvm_emit_raw_call(c, &res, prototype, llvm_func_type(c, prototype), val.value, actual_args,
count, 0, NULL, false, NULL);
llvm_emit_unreachable(c);
}
void llvm_emit_panic_if_true(GenContext *c, BEValue *value, const char *panic_name, SourceSpan loc, const char *fmt, BEValue *value_1,
@@ -1408,8 +1409,8 @@ void llvm_emit_panic_if_true(GenContext *c, BEValue *value, const char *panic_na
}
}
llvm_emit_panic(c, panic_name, loc, fmt, values);
llvm_emit_unreachable(c);
llvm_emit_block(c, ok_block);
EMIT_SPAN(c, loc);
}
void llvm_emit_panic_on_true(GenContext *c, LLVMValueRef value, const char *panic_name, SourceSpan loc,

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.4.701"
#define COMPILER_VERSION "0.4.702"

View File

@@ -47,10 +47,7 @@ assert_fail: ; preds = %loop.body
unreachable
assert_ok: ; preds = %loop.body
%10 = load i64, ptr %i, align 8
%neq1 = icmp ne i64 2, %10
call void @llvm.assume(i1 %neq1)
%11 = load i64, ptr %i, align 8
%add = add i64 %11, 1
%add = add i64 %10, 1
store i64 %add, ptr %i, align 8
br label %loop.cond
loop.exit: ; preds = %loop.cond