-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clang's -Wmissing-prototypes
isn't helpful for explicitly extern "C"
function definitions.
#94138
Comments
Another interesting case here are functions defined with |
Most of these are places where we failed to include a header file and simply never got an error about this. The fix is to include the header file. Most other cases are functions that should have been marked `static` but were not. Finding all of these was a main motivation for me enabling the warning despite how much work it is. One complicating factor was that we weren't including the `handle.h` for all the state-based handler functions. While this isn't a tiny amount of code, it is just declarations and doesn't add any extra dependencies. It also lets us have the checking for which functions need to be `static` and which don't. For the `parse` library I had to add the `handle.h` header as well, I tried to match the design of it in `check`. I have also had to work around a bug in the warning, but given the value it seems to be providing, that seems reasonable. I've filed the bug upstream: llvm/llvm-project#94138 I also had to use some hacks to work around limitations of Bazel rules that wrap `cc_library` rules and don't expose `copts`. I filed a bug for `cc_proto_library` specifically: bazelbuild/bazel#22610
See also #55018. |
Thanks for connecting the issues! I think the thing I disagree with is that there's nothing to do here. I think it would be good to restrict this warning so it doesn't fire for I'm not using |
|
It looks like libFuzzer specifically does not want to vend a header for this function - the contract that libFuzzer and other fuzzers are using is that the library should expose a function that matches that signature, written in documentation only. ( https://llvm.org/docs/LibFuzzer.html - "Note that this fuzz target does not depend on libFuzzer in any way and so it is possible and even desirable to use it with other fuzzing engines") This doesn't seem like a particularly uncommon use case - extern "C" APIs intended to be used from some other language that doesn't know about C, doesn't have C headers, and just says "have a symbol that matches this name and we'll pass it these arguments". But, yes, many C APIs of course do correspond with C headers and are implemented in C++ files, so I'm not sure turning the warning off entirely in these cases would be ideal. Having it under a subcategory seems fine to me, FWIW. |
Another possibility would be to have an attribute to specifically mark a function that is defined against some external ABI rather than against a declaration from a header file. Or a combination of a subcategory and an attribute. |
Most of these are places where we failed to include a header file and simply never got an error about this. The fix is to include the header file. Most other cases are functions that should have been marked `static` but were not. Finding all of these was a main motivation for me enabling the warning despite how much work it is. One complicating factor was that we weren't including the `handle.h` for all the state-based handler functions. While this isn't a tiny amount of code, it is just declarations and doesn't add any extra dependencies. It also lets us have the checking for which functions need to be `static` and which don't. For the `parse` library I had to add the `handle.h` header as well, I tried to match the design of it in `check`. I have also had to work around a bug in the warning, but given the value it seems to be providing, that seems reasonable. I've filed the bug upstream: llvm/llvm-project#94138 I also had to use some hacks to work around limitations of Bazel rules that wrap `cc_library` rules and don't expose `copts`. I filed a bug for `cc_proto_library` specifically: bazelbuild/bazel#22610
Most of these are places where we failed to include a header file and simply never got an error about this. The fix is to include the header file. Most other cases are functions that should have been marked `static` but were not. Finding all of these was a main motivation for me enabling the warning despite how much work it is. One complicating factor was that we weren't including the `handle.h` for all the state-based handler functions. While this isn't a tiny amount of code, it is just declarations and doesn't add any extra dependencies. It also lets us have the checking for which functions need to be `static` and which don't. For the `parse` library I had to add the `handle.h` header as well, I tried to match the design of it in `check`. I have also had to work around a bug in the warning, but given the value it seems to be providing, that seems reasonable. I've filed the bug upstream: llvm/llvm-project#94138 I also had to use some hacks to work around limitations of Bazel rules that wrap `cc_library` rules and don't expose `copts`. I filed a bug for `cc_proto_library` specifically: bazelbuild/bazel#22610
Thank you for raising this! I think this depends at least somewhat on what expectations are set for A confounding factor here is that Clang emits So the whole situation is a bit of a mess. I think the purpose to
This code has a problem in C and is perfectly fine in C++ (because you'd get the diagnostic you'd expect in that case). I did some historical digging to see if this was considered when the feature was worked on. The diagnostic was added in f1b876d5 and came with no discussion or tests, but was exposed for C++ functions. So this behavior has been this way in Clang since 2009 but it's not clear to me that it was an intentional design decision. |
Most of these are places where we failed to include a header file and simply never got an error about this. The fix is to include the header file. Most other cases are functions that should have been marked `static` but were not. Finding all of these was a main motivation for me enabling the warning despite how much work it is. One complicating factor was that we weren't including the `handle.h` for all the state-based handler functions. While this isn't a tiny amount of code, it is just declarations and doesn't add any extra dependencies. It also lets us have the checking for which functions need to be `static` and which don't. For the `parse` library I had to add the `handle.h` header as well, I tried to match the design of it in `check`. I have also had to work around a bug in the warning, but given the value it seems to be providing, that seems reasonable. I've filed the bug upstream: llvm/llvm-project#94138 I also had to use some hacks to work around limitations of Bazel rules that wrap `cc_library` rules and don't expose `copts`. I filed a bug for `cc_proto_library` specifically: ~bazelbuild/bazel#22610 bazelbuild/bazel#4446
I really like
-Wmissing-prototypes
for a lot of stuff, but it is firing on one pattern where it seems pretty unhelpful:The code in question is following LibFuzzer's documented guidance to define the fuzzer entry point:
The warning is technically correct that this definition has no prior prototype. However, by making it
extern "C"
there is a very clear signal that this is a known C ABI external entry point that we need to define, but may not have a header to declare for us. And suggesting to addstatic
when the function is declared explicitlyextern "C"
seems pretty confusing.Ideally I'd like to just disable this warning for
extern "C"
functions as it seems unlikely to be correct. If folks are specifically interested in retaining that, I'd love a flag to control that narrow behavior.The text was updated successfully, but these errors were encountered: