mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-29 02:06:06 +00:00

With D148785, -fsanitize=function no longer uses C++ RTTI objects and therefore can support C. The rationale for reporting errors is C11 6.5.2.2p9: > If the function is defined with a type that is not compatible with the type (of the expression) pointed to by the expression that denotes the called function, the behavior is undefined. The mangled types approach we use does not exactly match the C type compatibility (see `f(callee1)` below). This is probably fine as the rules are unlikely leveraged in practice. In addition, the call is warned by -Wincompatible-function-pointer-types-strict. ``` void callee0(int (*a)[]) {} void callee1(int (*a)[1]) {} void f(void (*fp)(int (*)[])) { fp(0); } int main() { int a[1]; f(callee0); f(callee1); // compatible but flagged by -fsanitize=function, -fsanitize=kcfi, and -Wincompatible-function-pointer-types-strict } ``` Skip indirect call sites of a function type without a prototype to avoid deal with C11 6.5.2.2p6. -fsanitize=kcfi skips such calls as well. Reviewed By: #sanitizers, vitalybuka Differential Revision: https://reviews.llvm.org/D148827
10 lines
397 B
C
10 lines
397 B
C
// RUN: %clang_cc1 -emit-llvm -triple x86_64 -std=c17 -fsanitize=function %s -o - | FileCheck %s
|
|
|
|
// CHECK-LABEL: define{{.*}} @call_no_prototype(
|
|
// CHECK-NOT: __ubsan_handle_function_type_mismatch
|
|
void call_no_prototype(void (*f)()) { f(); }
|
|
|
|
// CHECK-LABEL: define{{.*}} @call_prototype(
|
|
// CHECK: __ubsan_handle_function_type_mismatch
|
|
void call_prototype(void (*f)(void)) { f(); }
|