diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2026-01-26 18:23:29 +0000 |
|---|---|---|
| committer | gingerBill <gingerBill@users.noreply.github.com> | 2026-01-26 18:23:29 +0000 |
| commit | 3586bda6ae80b1dca1984ae54b023d5fec69067e (patch) | |
| tree | d1b8bba874b42fae91e12f095f10ad017bef9b34 /src/llvm_backend_expr.cpp | |
| parent | 467954bc7baed8061348b6dc5ddda1a742ea69f4 (diff) | |
Use `context.assertion_failure_proc` with type assertions when the `context` is available, otherwise use a trivial trap.
Diffstat (limited to 'src/llvm_backend_expr.cpp')
| -rw-r--r-- | src/llvm_backend_expr.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp index 3c7092a32..aba196af8 100644 --- a/src/llvm_backend_expr.cpp +++ b/src/llvm_backend_expr.cpp @@ -3865,7 +3865,12 @@ gb_internal lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) { args[4] = lb_typeid(p->module, src_type); args[5] = lb_typeid(p->module, dst_type); } - lb_emit_runtime_call(p, "type_assertion_check", args); + + char const *name = "type_assertion_check_contextless"; + if (p->context_stack.count > 0) { + name = "type_assertion_check_with_context"; + } + lb_emit_runtime_call(p, name, args); } lbValue data_ptr = v; @@ -3881,16 +3886,28 @@ gb_internal lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) { lbValue any_id = lb_emit_struct_ev(p, v, 1); + isize arg_count = 6; + if (build_context.no_rtti) { + arg_count = 4; + } + lbValue id = lb_typeid(p->module, type); lbValue ok = lb_emit_comp(p, Token_CmpEq, any_id, id); - auto args = array_make<lbValue>(permanent_allocator(), 6); + auto args = array_make<lbValue>(permanent_allocator(), arg_count); args[0] = ok; lb_set_file_line_col(p, array_slice(args, 1, args.count), pos); - args[4] = any_id; - args[5] = id; - lb_emit_runtime_call(p, "type_assertion_check", args); + if (!build_context.no_rtti) { + args[4] = any_id; + args[5] = id; + } + + char const *name = "type_assertion_check_contextless"; + if (p->context_stack.count > 0) { + name = "type_assertion_check_with_context"; + } + lb_emit_runtime_call(p, name, args); } return lb_emit_conv(p, data_ptr, tv.type); |