mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
committed by
GitHub
parent
4a50de8318
commit
cc9ca35e04
@@ -159,6 +159,14 @@ macro void unsupported(String string = "Unsupported function invoked") @builtin
|
||||
$$unreachable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unconditionally break into an attached debugger when reached.
|
||||
**/
|
||||
macro void breakpoint() @builtin
|
||||
{
|
||||
$$breakpoint();
|
||||
}
|
||||
|
||||
macro any_make(void* ptr, typeid type) @builtin
|
||||
{
|
||||
return $$any_make(ptr, type);
|
||||
|
||||
@@ -888,6 +888,7 @@ typedef enum
|
||||
BUILTIN_ATOMIC_FETCH_INC_WRAP,
|
||||
BUILTIN_ATOMIC_FETCH_DEC_WRAP,
|
||||
BUILTIN_BITREVERSE,
|
||||
BUILTIN_BREAKPOINT,
|
||||
BUILTIN_BSWAP,
|
||||
BUILTIN_CEIL,
|
||||
BUILTIN_COMPARE_EXCHANGE,
|
||||
|
||||
@@ -740,6 +740,7 @@ static void llvm_codegen_setup()
|
||||
intrinsic_id.ctlz = lookup_intrinsic("llvm.ctlz");
|
||||
intrinsic_id.ctpop = lookup_intrinsic("llvm.ctpop");
|
||||
intrinsic_id.cttz = lookup_intrinsic("llvm.cttz");
|
||||
intrinsic_id.debugtrap = lookup_intrinsic("llvm.debugtrap");
|
||||
intrinsic_id.exp = lookup_intrinsic("llvm.exp");
|
||||
intrinsic_id.exp2 = lookup_intrinsic("llvm.exp2");
|
||||
intrinsic_id.expect = lookup_intrinsic("llvm.expect");
|
||||
|
||||
@@ -888,6 +888,9 @@ void llvm_emit_builtin_call(GenContext *c, BEValue *result_value, Expr *expr)
|
||||
case BUILTIN_TRAP:
|
||||
llvm_value_set(result_value, llvm_emit_call_intrinsic(c, intrinsic_id.trap, NULL, 0, NULL, 0), type_void);
|
||||
return;
|
||||
case BUILTIN_BREAKPOINT:
|
||||
llvm_value_set(result_value, llvm_emit_call_intrinsic(c, intrinsic_id.debugtrap, NULL, 0, NULL, 0), type_void);
|
||||
return;
|
||||
case BUILTIN_PREFETCH:
|
||||
llvm_emit_prefetch(c, result_value, expr);
|
||||
return;
|
||||
|
||||
@@ -221,6 +221,7 @@ typedef struct
|
||||
unsigned ssub_overflow;
|
||||
unsigned ssub_sat;
|
||||
unsigned trap;
|
||||
unsigned debugtrap;
|
||||
unsigned trunc;
|
||||
unsigned uadd_overflow;
|
||||
unsigned uadd_sat;
|
||||
|
||||
@@ -415,8 +415,10 @@ bool sema_expr_analyse_builtin_call(SemaContext *context, Expr *expr)
|
||||
return sema_expr_analyse_syscall(context, expr);
|
||||
case BUILTIN_TRAP:
|
||||
case BUILTIN_UNREACHABLE:
|
||||
expr->type = type_void;
|
||||
expr->call_expr.no_return = true;
|
||||
FALLTHROUGH;
|
||||
case BUILTIN_BREAKPOINT:
|
||||
expr->type = type_void;
|
||||
return true;
|
||||
case BUILTIN_SYSCLOCK:
|
||||
expr->type = type_ulong;
|
||||
@@ -1002,6 +1004,7 @@ bool sema_expr_analyse_builtin_call(SemaContext *context, Expr *expr)
|
||||
case BUILTIN_SWIZZLE2:
|
||||
case BUILTIN_SYSCLOCK:
|
||||
case BUILTIN_TRAP:
|
||||
case BUILTIN_BREAKPOINT:
|
||||
case BUILTIN_UNREACHABLE:
|
||||
UNREACHABLE
|
||||
}
|
||||
@@ -1022,6 +1025,7 @@ static inline int builtin_expected_args(BuiltinFunction func)
|
||||
case BUILTIN_GET_ROUNDING_MODE:
|
||||
case BUILTIN_SYSCLOCK:
|
||||
case BUILTIN_TRAP:
|
||||
case BUILTIN_BREAKPOINT:
|
||||
case BUILTIN_UNREACHABLE:
|
||||
return 0;
|
||||
case BUILTIN_ABS:
|
||||
|
||||
@@ -190,6 +190,7 @@ void symtab_init(uint32_t capacity)
|
||||
builtin_list[BUILTIN_ATOMIC_FETCH_INC_WRAP] = KW_DEF("atomic_fetch_inc_wrap");
|
||||
builtin_list[BUILTIN_ATOMIC_FETCH_DEC_WRAP] = KW_DEF("atomic_fetch_dec_wrap");
|
||||
builtin_list[BUILTIN_BITREVERSE] = KW_DEF("bitreverse");
|
||||
builtin_list[BUILTIN_BREAKPOINT] = KW_DEF("breakpoint");
|
||||
builtin_list[BUILTIN_BSWAP] = KW_DEF("bswap");
|
||||
builtin_list[BUILTIN_CEIL] = KW_DEF("ceil");
|
||||
builtin_list[BUILTIN_COMPARE_EXCHANGE] = KW_DEF(("compare_exchange"));
|
||||
|
||||
12
test/test_suite/builtins/trap.c3t
Normal file
12
test/test_suite/builtins/trap.c3t
Normal file
@@ -0,0 +1,12 @@
|
||||
module test;
|
||||
|
||||
fn void main()
|
||||
{
|
||||
$$breakpoint();
|
||||
$$trap();
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
call void @llvm.debugtrap()
|
||||
call void @llvm.trap()
|
||||
Reference in New Issue
Block a user