blob: 9f1855baeb5d302b37542ec1e716f5db572222e4 [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
Hans Wennborg68e3aa72016-05-11 00:49:20 +00006// Check that the warning is disabled by default:
7// RUN: %clang_cc1 -fms-extensions -triple i686-pc-windows-msvc -DMSVC -Werror -Wno-pointer-bool-conversion -x c %s
8
Reid Kleckner9f497332016-05-10 21:00:03 +00009// expected-note@+1 {{consider defining 'mismatched_before_winapi' with the 'stdcall' calling convention}}
10void mismatched_before_winapi(int x) {}
11
12#ifdef MSVC
13#define WINAPI __stdcall
14#else
15#define WINAPI __attribute__((stdcall))
16#endif
17
18// expected-note@+1 3 {{consider defining 'mismatched' with the 'stdcall' calling convention}}
19void mismatched(int x) {}
20
21typedef void (WINAPI *callback_t)(int);
22void take_callback(callback_t callback);
23
24int main() {
25 // expected-warning@+1 {{cast between incompatible calling conventions 'cdecl' and 'stdcall'}}
26 take_callback((callback_t)mismatched);
27
28 // expected-warning@+1 {{cast between incompatible calling conventions 'cdecl' and 'stdcall'}}
29 callback_t callback = (callback_t)mismatched; // warns
30 (void)callback;
31
32 // expected-warning@+1 {{cast between incompatible calling conventions 'cdecl' and 'stdcall'}}
33 callback = (callback_t)&mismatched; // warns
34
35 // No warning, just to show we don't drill through other kinds of unary operators.
36 callback = (callback_t)!mismatched;
37
38 // expected-warning@+1 {{cast between incompatible calling conventions 'cdecl' and 'stdcall'}}
39 callback = (callback_t)&mismatched_before_winapi; // warns
40
41 // Probably a bug, but we don't warn.
42 void (*callback2)(int) = mismatched;
43 take_callback((callback_t)callback2);
44
45 // Another way to suppress the warning.
46 take_callback((callback_t)(void*)mismatched);
47}
48
Hans Wennborg68e3aa72016-05-11 00:49:20 +000049// MSFIXIT: fix-it:"{{.*}}callingconv-cast.c":{19:6-19:6}:"WINAPI "
50// MSFIXIT: fix-it:"{{.*}}callingconv-cast.c":{19:6-19:6}:"WINAPI "
51// MSFIXIT: fix-it:"{{.*}}callingconv-cast.c":{19:6-19:6}:"WINAPI "
52// MSFIXIT: fix-it:"{{.*}}callingconv-cast.c":{10:6-10:6}:"__stdcall "
Reid Kleckner9f497332016-05-10 21:00:03 +000053
Hans Wennborg68e3aa72016-05-11 00:49:20 +000054// GNUFIXIT: fix-it:"{{.*}}callingconv-cast.c":{19:6-19:6}:"WINAPI "
55// GNUFIXIT: fix-it:"{{.*}}callingconv-cast.c":{19:6-19:6}:"WINAPI "
56// GNUFIXIT: fix-it:"{{.*}}callingconv-cast.c":{19:6-19:6}:"WINAPI "
57// GNUFIXIT: fix-it:"{{.*}}callingconv-cast.c":{10:6-10:6}:"__attribute__((stdcall)) "