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 | |
Reid Kleckner | 43be52a | 2016-05-11 17:43:13 +0000 | [diff] [blame^] | 24 | void WINAPI mismatched_stdcall(int x) {} |
| 25 | |
| 26 | void take_opaque_fn(void (*callback)(int)); |
| 27 | |
Reid Kleckner | 9f49733 | 2016-05-10 21:00:03 +0000 | [diff] [blame] | 28 | int 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 Kleckner | 43be52a | 2016-05-11 17:43:13 +0000 | [diff] [blame^] | 51 | |
| 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 Kleckner | 9f49733 | 2016-05-10 21:00:03 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Hans Wennborg | 68e3aa7 | 2016-05-11 00:49:20 +0000 | [diff] [blame] | 58 | // 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 Kleckner | 9f49733 | 2016-05-10 21:00:03 +0000 | [diff] [blame] | 62 | |
Hans Wennborg | 68e3aa7 | 2016-05-11 00:49:20 +0000 | [diff] [blame] | 63 | // 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)) " |