[Clang][Sema] Add -Wincompatible-function-pointer-types-strict
authorSami Tolvanen <samitolvanen@google.com>
Mon, 7 Nov 2022 22:55:24 +0000 (22:55 +0000)
committerSami Tolvanen <samitolvanen@google.com>
Mon, 7 Nov 2022 23:05:28 +0000 (23:05 +0000)
commit41ce74e6e983f523d44d3a80be5ae778c35df85a
tree569d13b36c41c10bda320025407c8ac1c5e5d2f8
parentf64802e8d3e9db299cad913ffcb734c8d35dc5f0
[Clang][Sema] Add -Wincompatible-function-pointer-types-strict

Clang supports indirect call Control-Flow Integrity (CFI) sanitizers
(e.g. -fsanitize=cfi-icall), which enforce an exact type match
between a function pointer and the target function. Unfortunately,
Clang doesn't provide diagnostics that help developers avoid
function pointer assignments that can lead to runtime CFI
failures. -Wincompatible-function-pointer-types doesn't warn about
enum to integer mismatches if the types are otherwise compatible, for
example, which isn't sufficient with CFI.

Add -Wincompatible-function-pointer-types-strict, which checks for a
stricter function type compatibility in assignments and helps warn about
assignments that can potentially lead to CFI failures.

Reviewed By: aaron.ballman, nickdesaulniers

Differential Revision: https://reviews.llvm.org/D136790
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/incompatible-function-pointer-types-strict.c [new file with mode: 0644]