Skip to content

Inconsistent (missing) incompatible function pointer type warnings #41465

Open
@brunodefraine

Description

@brunodefraine
Bugzilla Link 42120
Version trunk
OS All
CC @dwblaikie,@DougGregor,@zygoloid

Extended Description

Clang marks pointer conversions that add noreturn or noescape information to function types as incompatible (while removing such information is fine), but this warning is not consistent:

$ cat test.c
void fun00(int *);
void fun01(int *) __attribute__((noreturn));
void fun10(__attribute__((noescape)) int *);
void fun11(__attribute__((noescape)) int *) __attribute__((noreturn));

// OK: safe, no warning
void (*fptr01)(int *) = &fun01;
void (*fptr02)(__attribute__((noescape)) int *) = &fun11;
void (*fptr03)(int *) __attribute__((noreturn)) = &fun11;

// OK: unsafe, warning
void (*fptr11)(int *) __attribute__((noreturn)) = &fun00;
void (*fptr12)(__attribute__((noescape)) int *) = &fun00;
void (*fptr13)(__attribute__((noescape)) int *) __attribute__((noreturn)) = &fun00;

// NOT OK: also unsafe, no warning?
void (*fptr14)(__attribute__((noescape)) int *) = &fun01;
void (*fptr15)(int *) __attribute__((noreturn)) = &fun10;
$ clang -c -x c test.c
(only cases fptr11, fptr12, fptr13 are warnings; fptr14 and fptr15 pass without warning/error)

Godbolt: https://godbolt.org/z/XjFsFB

That no warnings are issued for fptr14 and fptr15 cases seems wrong. The conversions are at least as dangerous as the fptr11 and fptr12 cases, which do get warnings.

Note that C++ behavior:

$ clang -c -x c++ test.c
(cases fptr11, fptr12, fptr12, fptr13, fptr14, fptr15 are flagged as errors)

Godbolt: https://godbolt.org/z/cVjcCQ

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillacclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions