mirror of
https://github.com/odin-lang/Odin.git
synced 2026-02-13 06:43:35 +00:00
Make unreachable() a built-in compiler-level procedure
This commit is contained in:
@@ -785,17 +785,3 @@ unimplemented :: proc(message := "", loc := #caller_location) -> ! {
|
||||
}
|
||||
p("not yet implemented", message, loc)
|
||||
}
|
||||
|
||||
@builtin
|
||||
@(disabled=ODIN_DISABLE_ASSERT)
|
||||
unreachable :: proc(message := "", loc := #caller_location) -> ! {
|
||||
p := context.assertion_failure_proc
|
||||
if p == nil {
|
||||
p = default_assertion_failure_proc
|
||||
}
|
||||
if message != "" {
|
||||
p("internal error", message, loc)
|
||||
} else {
|
||||
p("internal error", "entered unreachable code", loc)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3569,6 +3569,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
|
||||
operand->mode = Addressing_NoValue;
|
||||
break;
|
||||
|
||||
case BuiltinProc_unreachable:
|
||||
case BuiltinProc_trap:
|
||||
case BuiltinProc_debug_trap:
|
||||
operand->mode = Addressing_NoValue;
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
bool is_diverging_stmt(Ast *stmt) {
|
||||
if (stmt->kind != Ast_ExprStmt) {
|
||||
return false;
|
||||
}
|
||||
Ast *expr = unparen_expr(stmt->ExprStmt.expr);
|
||||
bool is_diverging_expr(Ast *expr) {
|
||||
expr = unparen_expr(expr);
|
||||
if (expr->kind != Ast_CallExpr) {
|
||||
return false;
|
||||
}
|
||||
@@ -26,6 +23,12 @@ bool is_diverging_stmt(Ast *stmt) {
|
||||
t = base_type(t);
|
||||
return t != nullptr && t->kind == Type_Proc && t->Proc.diverging;
|
||||
}
|
||||
bool is_diverging_stmt(Ast *stmt) {
|
||||
if (stmt->kind != Ast_ExprStmt) {
|
||||
return false;
|
||||
}
|
||||
return is_diverging_expr(stmt->ExprStmt.expr);
|
||||
}
|
||||
|
||||
bool contains_deferred_call(Ast *node) {
|
||||
if (node->viral_state_flags & ViralStateFlag_ContainsDeferredProcedure) {
|
||||
|
||||
@@ -40,6 +40,8 @@ enum BuiltinProcId {
|
||||
BuiltinProc_hadamard_product,
|
||||
BuiltinProc_matrix_flatten,
|
||||
|
||||
BuiltinProc_unreachable,
|
||||
|
||||
BuiltinProc_DIRECTIVE, // NOTE(bill): This is used for specialized hash-prefixed procedures
|
||||
|
||||
// "Intrinsics"
|
||||
@@ -330,6 +332,8 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
|
||||
{STR_LIT("hadamard_product"), 2, false, Expr_Expr, BuiltinProcPkg_builtin},
|
||||
{STR_LIT("matrix_flatten"), 1, false, Expr_Expr, BuiltinProcPkg_builtin},
|
||||
|
||||
{STR_LIT("unreachable"), 0, false, Expr_Expr, BuiltinProcPkg_builtin, /*diverging*/true},
|
||||
|
||||
{STR_LIT(""), 0, true, Expr_Expr, BuiltinProcPkg_builtin}, // DIRECTIVE
|
||||
|
||||
|
||||
@@ -341,7 +345,7 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
|
||||
{STR_LIT("alloca"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("cpu_relax"), 0, false, Expr_Stmt, BuiltinProcPkg_intrinsics},
|
||||
|
||||
{STR_LIT("trap"), 0, false, Expr_Stmt, BuiltinProcPkg_intrinsics, /*diverging*/true},
|
||||
{STR_LIT("trap"), 0, false, Expr_Expr, BuiltinProcPkg_intrinsics, /*diverging*/true},
|
||||
{STR_LIT("debug_trap"), 0, false, Expr_Stmt, BuiltinProcPkg_intrinsics, /*diverging*/false},
|
||||
{STR_LIT("read_cycle_counter"), 0, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
|
||||
|
||||
@@ -1851,6 +1851,11 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
|
||||
return lb_emit_matrix_flatten(p, m, tv.type);
|
||||
}
|
||||
|
||||
case BuiltinProc_unreachable:
|
||||
LLVMBuildUnreachable(p->builder);
|
||||
return {};
|
||||
|
||||
|
||||
// "Intrinsics"
|
||||
|
||||
case BuiltinProc_alloca:
|
||||
|
||||
Reference in New Issue
Block a user