r269116 - Add -Wcast-calling-convention to warn when casting away calling conventions

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Wed May 11 09:37:27 PDT 2016


On Tue, May 10, 2016 at 5:55 PM, Hans Wennborg <hans at chromium.org> wrote:
>> This warning is currently off by default while we study its usefulness.
>
> Turns out this wasn't true :-) For example, it's firing here:
> https://build.chromium.org/p/chromium.fyi/builders/ClangToTWin%28dbg%29/builds/5569/steps/compile/logs/stdio
>
> Adding DefaultIgnore in r269148.

Oops, thanks. I think I was going to run it over Chromium myself, and
then I changed my mind, and forgot to change it back.

---

Based on the two warning instances in that Mesa build, I think we
should relax this warning when casting from a non-standard convention
to a default convention. We could also consider relaxing the warning
when casting to a void function, since that's what people seem to use
to mean "generic function pointer". The code in question is doing
stuff like:

void __stdcall api_func0(int a) { ... }
void __stdcall api_func1(int a, int b) { ... }
...
typedef void (*func_ty)();
func_ty api_entries[] = {
  (func_ty) &api_func0,
  (func_ty) &api_func1,
  ...
};

Our fixit suggestions are also very silly, because the functions in
question already have explicit calling convention attributes:

..\..\third_party\mesa\src\chromium_gensrc\mesa\glapi_mapi_tmp_shared.h(12817,15):
 note: consider defining 'shared_dispatch_stub_2' with the 'cdecl'
calling convention
void APIENTRY shared_dispatch_stub_2(GLuint list)
              ^
              CDECL_NON_WVMPURE


More information about the cfe-commits mailing list