blob: 88b25e8f17a430664f5d535fe0d09025e54b9c5b [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
Reid Kleckner43be52a2016-05-11 17:43:13 +000024void WINAPI mismatched_stdcall(int x) {}
25
26void take_opaque_fn(void (*callback)(int));
27
Reid Kleckner9f497332016-05-10 21:00:03 +000028int main() {
29 // expected-warning@+1 {{cast between incompatible calling conventions 'cdecl' and 'stdcall'}}
30 take_callback((callback_t)mismatched);
31
32 // expected-warning@+1 {{cast between incompatible calling conventions 'cdecl' and 'stdcall'}}
33 callback_t callback = (callback_t)mismatched; // warns
34 (void)callback;
35
36 // expected-warning@+1 {{cast between incompatible calling conventions 'cdecl' and 'stdcall'}}
37 callback = (callback_t)&mismatched; // warns
38
39 // No warning, just to show we don't drill through other kinds of unary operators.
40 callback = (callback_t)!mismatched;
41
42 // expected-warning@+1 {{cast between incompatible calling conventions 'cdecl' and 'stdcall'}}
43 callback = (callback_t)&mismatched_before_winapi; // warns
44
45 // Probably a bug, but we don't warn.
46 void (*callback2)(int) = mismatched;
47 take_callback((callback_t)callback2);
48
49 // Another way to suppress the warning.
50 take_callback((callback_t)(void*)mismatched);
Reid Kleckner43be52a2016-05-11 17:43:13 +000051
52 // Don't warn, because we're casting from stdcall to cdecl. Usually that means
53 // the programmer is rinsing the function pointer through some kind of opaque
54 // API.
55 take_opaque_fn((void (*)(int))mismatched_stdcall);
Reid Kleckner9f497332016-05-10 21:00:03 +000056}
57
Hans Wennborg68e3aa72016-05-11 00:49:20 +000058// MSFIXIT: fix-it:"{{.*}}callingconv-cast.c":{19:6-19:6}:"WINAPI "
59// MSFIXIT: fix-it:"{{.*}}callingconv-cast.c":{19:6-19:6}:"WINAPI "
60// MSFIXIT: fix-it:"{{.*}}callingconv-cast.c":{19:6-19:6}:"WINAPI "
61// MSFIXIT: fix-it:"{{.*}}callingconv-cast.c":{10:6-10:6}:"__stdcall "
Reid Kleckner9f497332016-05-10 21:00:03 +000062
Hans Wennborg68e3aa72016-05-11 00:49:20 +000063// GNUFIXIT: fix-it:"{{.*}}callingconv-cast.c":{19:6-19:6}:"WINAPI "
64// GNUFIXIT: fix-it:"{{.*}}callingconv-cast.c":{19:6-19:6}:"WINAPI "
65// GNUFIXIT: fix-it:"{{.*}}callingconv-cast.c":{19:6-19:6}:"WINAPI "
66// GNUFIXIT: fix-it:"{{.*}}callingconv-cast.c":{10:6-10:6}:"__attribute__((stdcall)) "