Skip to content

[clang] C mode -Wincompatible-function-pointer-types diag disappears in case of other function type differences #160474

@brunodf-snps

Description

@brunodf-snps

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerduplicateResolved as duplicate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions