mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 03:56:06 +00:00

Implicitly converting between incompatible function pointers in C is currently a default-on warning (it is an error in C++). However, this is very poor security posture. A mismatch in parameters or return types, or a mismatch in calling conventions, etc can lead to exploitable security vulnerabilities. Rather than allow this unsafe practice with a warning, this patch strengthens the warning to be an error (while still allowing users the ability to disable the error or the warning entirely to ease migration). Users should either ensure the signatures are correctly compatible or they should use an explicit cast if they believe that's more reasonable. Differential Revision: https://reviews.llvm.org/D131351
10 lines
372 B
C
10 lines
372 B
C
// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-pc-win32 %s
|
|
|
|
void __attribute__((ms_abi)) foo(void);
|
|
void (*pfoo)(void) = foo;
|
|
|
|
void __attribute__((sysv_abi)) bar(void);
|
|
void (*pbar)(void) = bar; // expected-error{{incompatible function pointer types}}
|
|
|
|
void (__attribute__((sysv_abi)) *pfoo2)(void) = foo; // expected-error{{incompatible function pointer types}}
|