[llvm-bugs] [Bug 42120] New: Inconsistent (missing) incompatible function pointer type warnings

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jun 4 01:33:12 PDT 2019


            Bug ID: 42120
           Summary: Inconsistent (missing) incompatible function pointer
                    type warnings
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: bruno-llvm at defraine.net
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

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)) =

// 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

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

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190604/ee41d7ea/attachment.html>

More information about the llvm-bugs mailing list