Null-check function pointer invocation #1573.

This commit is contained in:
Christoffer Lerno
2024-10-26 18:41:47 +02:00
parent b187d5a3fc
commit cc6a24cf80
3 changed files with 54 additions and 0 deletions

View File

@@ -6206,6 +6206,16 @@ static void llvm_emit_call_expr(GenContext *c, BEValue *result_value, Expr *expr
// 1d. Load it as a value
func = llvm_load_value_store(c, &func_value);
if (safe_mode_enabled())
{
LLVMValueRef check = LLVMBuildICmp(c->builder, LLVMIntEQ, func, LLVMConstNull(c->ptr_type), "checknull");
scratch_buffer_clear();
scratch_buffer_append("Calling null function pointer, '");
span_to_scratch(function->span);
scratch_buffer_append("' was null.");
llvm_emit_panic_on_true(c, check, scratch_buffer_to_string(), function->span, NULL, NULL, NULL);
}
// 1e. Calculate the function type
func_type = llvm_get_type(c, type);
}