[clang] C mode -Wincompatible-function-pointer-types diag disappears in case of other function type differences
This is explored in the following test cases. All lines marked "OK??" are cases where a diagnostic is logically missing (and gcc has a diagnostic if it understand the involved attributes).
Godbolt demo: https://godbolt.org/z/f3o8KoqGo
#ifdef __clang__
// Comment-in pragma to enable strict mode
//#pragma clang diagnostic warning "-Wincompatible-function-pointer-types-strict"
#endif
enum E { A = -1, B };
// Case 1: assignment adding noreturn
int f1 (int);
int (*fp1a)(int) __attribute__((noreturn)) = &f1; // NOK
enum E (*fp1b)(int) __attribute__((noreturn)) = &f1; // OK??
int (*fp1c)() __attribute__((noreturn)) = &f1; // OK??
#ifdef __clang__
// Case 2: assignment adding noescape on arg
int f2 (int* ) __attribute__((noreturn));
int (*fp2a)(int* __attribute__((noescape))) __attribute__((noreturn)) = &f2; // NOK
int (*fp2b)(int* __attribute__((noescape))) = &f2; // OK??
// Case 3: assignment adding cfi_unchecked_callee
int f3 (int* );
int (*fp3a)(int* ) __attribute__((noreturn )) = &f3; // NOK
int (*fp3b)(int* __attribute__((noescape))) = &f3; // NOK
int (*fp3c)(int* ) __attribute__((noreturn,cfi_unchecked_callee)) = &f3; // OK??
int (*fp3d)(int* __attribute__((noescape))) __attribute__(( cfi_unchecked_callee)) = &f3; // OK??
int (*fp3e)(int* __attribute__((noescape))) __attribute__((noreturn,cfi_unchecked_callee)) = &f3; // OK??
#endif
// Case 4: assignment to function with no prototype
int f4 (int);
int (*fp4a)(int) = &f4; // OK
int (*fp4b)() = &f4; // NOK for strict?
This issue was previously reported as https://bugs.llvm.org/show_bug.cgi?id=42120
A stricter diagnostic -Wincompatible-function-pointer-types-strict was added, this catches all the cases, but this also diagnoses differences in argument and result types that are allowed in C.
The old issues are available in github: https://github.com/llvm/llvm-project/issues/41465 should we close this as a duplicate and extend the older report?
The old issues are available in github: #41465 should we close this as a duplicate and extend the older report?
Thanks I did not realize! I added the information to the original report and I'm closing this as a duplicate.
@llvm/issue-subscribers-c
Author: Bruno De Fraine (brunodf-snps)
Godbolt demo: https://godbolt.org/z/f3o8KoqGo
#ifdef __clang__
// Comment-in pragma to enable strict mode
//#pragma clang diagnostic warning "-Wincompatible-function-pointer-types-strict"
#endif
enum E { A = -1, B };
// Case 1: assignment adding noreturn
int f1 (int);
int (*fp1a)(int) __attribute__((noreturn)) = &f1; // NOK
enum E (*fp1b)(int) __attribute__((noreturn)) = &f1; // OK??
int (*fp1c)() __attribute__((noreturn)) = &f1; // OK??
#ifdef __clang__
// Case 2: assignment adding noescape on arg
int f2 (int* ) __attribute__((noreturn));
int (*fp2a)(int* __attribute__((noescape))) __attribute__((noreturn)) = &f2; // NOK
int (*fp2b)(int* __attribute__((noescape))) = &f2; // OK??
// Case 3: assignment adding cfi_unchecked_callee
int f3 (int* );
int (*fp3a)(int* ) __attribute__((noreturn )) = &f3; // NOK
int (*fp3b)(int* __attribute__((noescape))) = &f3; // NOK
int (*fp3c)(int* ) __attribute__((noreturn,cfi_unchecked_callee)) = &f3; // OK??
int (*fp3d)(int* __attribute__((noescape))) __attribute__(( cfi_unchecked_callee)) = &f3; // OK??
int (*fp3e)(int* __attribute__((noescape))) __attribute__((noreturn,cfi_unchecked_callee)) = &f3; // OK??
#endif
// Case 4: assignment to function with no prototype
int f4 (int);
int (*fp4a)(int) = &f4; // OK
int (*fp4b)() = &f4; // NOK for strict?
This issue was previously reported as https://bugs.llvm.org/show_bug.cgi?id=42120
A stricter diagnostic -Wincompatible-function-pointer-types-strict was added, this catches all the cases, but this also diagnoses differences in argument and result types that are allowed in C.