• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 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}}
mismatched_before_winapi(int x)7 void 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}}
mismatched(int x)16 void mismatched(int x) {}
17 
18 typedef void (WINAPI *callback_t)(int);
19 void take_callback(callback_t callback);
20 
mismatched_stdcall(int x)21 void WINAPI mismatched_stdcall(int x) {}
22 
23 void take_opaque_fn(void (*callback)(int));
24 
main()25 int 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);
48 
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);
53 }
54 
55 // 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 "
59 
60 // 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)) "
64