Reid Kleckner | 9f49733 | 2016-05-10 21:00:03 +0000 | [diff] [blame] | 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 | |
Hans Wennborg | 68e3aa7 | 2016-05-11 00:49:20 +0000 | [diff] [blame] | 6 | // 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 Kleckner | 9f49733 | 2016-05-10 21:00:03 +0000 | [diff] [blame] | 9 | // expected-note@+1 {{consider defining 'mismatched_before_winapi' with the 'stdcall' calling convention}} |
| 10 | void 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}} |
| 19 | void mismatched(int x) {} |
| 20 | |
| 21 | typedef void (WINAPI *callback_t)(int); |
| 22 | void take_callback(callback_t callback); |
| 23 | |
| 24 | int 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 Wennborg | 68e3aa7 | 2016-05-11 00:49:20 +0000 | [diff] [blame] | 49 | // 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 Kleckner | 9f49733 | 2016-05-10 21:00:03 +0000 | [diff] [blame] | 53 | |
Hans Wennborg | 68e3aa7 | 2016-05-11 00:49:20 +0000 | [diff] [blame] | 54 | // 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)) " |