blob: 12c0dcbc256acf00aa2f00311366480c8f3374e0 [file] [log] [blame]
Reid Kleckner9f497332016-05-10 21:00:03 +00001// RUN: %clang_cc1 -fms-extensions -triple i686-pc-windows-msvc -Wcast-calling-convention -DMSVC -Wno-pointer-bool-conversion -verify -x c %s
2// RUN: %clang_cc1 -fms-extensions -triple i686-pc-windows-msvc -Wcast-calling-convention -DMSVC -Wno-pointer-bool-conversion -verify -x c++ %s
3// RUN: %clang_cc1 -fms-extensions -triple i686-pc-windows-msvc -Wcast-calling-convention -DMSVC -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s --check-prefix=MSFIXIT
4// RUN: %clang_cc1 -triple i686-pc-windows-gnu -Wcast-calling-convention -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s --check-prefix=GNUFIXIT
5
6// expected-note@+1 {{consider defining 'mismatched_before_winapi' with the 'stdcall' calling convention}}
7void mismatched_before_winapi(int x) {}
8
9#ifdef MSVC
10#define WINAPI __stdcall
11#else
12#define WINAPI __attribute__((stdcall))
13#endif
14
15// expected-note@+1 3 {{consider defining 'mismatched' with the 'stdcall' calling convention}}
16void mismatched(int x) {}
17
18typedef void (WINAPI *callback_t)(int);
19void take_callback(callback_t callback);
20
Reid Kleckner43be52a2016-05-11 17:43:13 +000021void WINAPI mismatched_stdcall(int x) {}
22
23void take_opaque_fn(void (*callback)(int));
24
Reid Kleckner9f497332016-05-10 21:00:03 +000025int main() {
26 // expected-warning@+1 {{cast between incompatible calling conventions 'cdecl' and 'stdcall'}}
27 take_callback((callback_t)mismatched);
28
29 // expected-warning@+1 {{cast between incompatible calling conventions 'cdecl' and 'stdcall'}}
30 callback_t callback = (callback_t)mismatched; // warns
31 (void)callback;
32
33 // expected-warning@+1 {{cast between incompatible calling conventions 'cdecl' and 'stdcall'}}
34 callback = (callback_t)&mismatched; // warns
35
36 // No warning, just to show we don't drill through other kinds of unary operators.
37 callback = (callback_t)!mismatched;
38
39 // expected-warning@+1 {{cast between incompatible calling conventions 'cdecl' and 'stdcall'}}
40 callback = (callback_t)&mismatched_before_winapi; // warns
41
42 // Probably a bug, but we don't warn.
43 void (*callback2)(int) = mismatched;
44 take_callback((callback_t)callback2);
45
46 // Another way to suppress the warning.
47 take_callback((callback_t)(void*)mismatched);
Reid Kleckner43be52a2016-05-11 17:43:13 +000048
49 // Don't warn, because we're casting from stdcall to cdecl. Usually that means
50 // the programmer is rinsing the function pointer through some kind of opaque
51 // API.
52 take_opaque_fn((void (*)(int))mismatched_stdcall);
Reid Kleckner9f497332016-05-10 21:00:03 +000053}
54
Reid Klecknera6fd8652016-05-17 17:33:31 +000055// MSFIXIT: fix-it:"{{.*}}callingconv-cast.c":{16:6-16:6}:"WINAPI "
56// MSFIXIT: fix-it:"{{.*}}callingconv-cast.c":{16:6-16:6}:"WINAPI "
57// MSFIXIT: fix-it:"{{.*}}callingconv-cast.c":{16:6-16:6}:"WINAPI "
58// MSFIXIT: fix-it:"{{.*}}callingconv-cast.c":{7:6-7:6}:"__stdcall "
Reid Kleckner9f497332016-05-10 21:00:03 +000059
Reid Klecknera6fd8652016-05-17 17:33:31 +000060// GNUFIXIT: fix-it:"{{.*}}callingconv-cast.c":{16:6-16:6}:"WINAPI "
61// GNUFIXIT: fix-it:"{{.*}}callingconv-cast.c":{16:6-16:6}:"WINAPI "
62// GNUFIXIT: fix-it:"{{.*}}callingconv-cast.c":{16:6-16:6}:"WINAPI "
63// GNUFIXIT: fix-it:"{{.*}}callingconv-cast.c":{7:6-7:6}:"__attribute__((stdcall)) "