Aaron Ballman | 1c8a5d7 | 2014-07-06 20:04:10 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple i386-mingw32 -fsyntax-only -Wno-missing-declarations -verify -fms-extensions %s |
| 2 | __stdcall int func0(void); |
| 3 | int __stdcall func(void); |
| 4 | typedef int (__cdecl *tptr)(void); |
| 5 | void (*__fastcall fastpfunc)(void); |
| 6 | extern __declspec(dllimport) void __stdcall VarR4FromDec(void); |
Steve Naroff | 44ac777 | 2008-12-25 14:16:32 +0000 | [diff] [blame] | 7 | __declspec(deprecated) __declspec(deprecated) char * __cdecl ltoa( long _Val, char * _DstBuf, int _Radix); |
David Majnemer | 1bf0f8e | 2015-07-20 22:51:52 +0000 | [diff] [blame] | 8 | __declspec(safebuffers) __declspec(noalias) __declspec(restrict) void * __cdecl xxx(void *_Memory); /* expected-warning{{__declspec attribute 'safebuffers' is not supported}} */ |
Steve Naroff | f9c29d4 | 2008-12-25 14:41:26 +0000 | [diff] [blame] | 9 | typedef __w64 unsigned long ULONG_PTR, *PULONG_PTR; |
Francois Pichet | f2fb411 | 2011-08-25 00:36:46 +0000 | [diff] [blame] | 10 | |
Aaron Ballman | 1c8a5d7 | 2014-07-06 20:04:10 +0000 | [diff] [blame] | 11 | void * __ptr64 PtrToPtr64(const void *p) { |
John McCall | 8d32c05 | 2012-05-22 21:28:12 +0000 | [diff] [blame] | 12 | return((void * __ptr64) (unsigned __int64) (ULONG_PTR)p ); |
Steve Naroff | f9c29d4 | 2008-12-25 14:41:26 +0000 | [diff] [blame] | 13 | } |
Aaron Ballman | 1c8a5d7 | 2014-07-06 20:04:10 +0000 | [diff] [blame] | 14 | |
| 15 | void * __ptr32 PtrToPtr32(const void *p) { |
John McCall | 8d32c05 | 2012-05-22 21:28:12 +0000 | [diff] [blame] | 16 | return((void * __ptr32) (unsigned __int32) (ULONG_PTR)p ); |
Francois Pichet | f2fb411 | 2011-08-25 00:36:46 +0000 | [diff] [blame] | 17 | } |
| 18 | |
Aaron Ballman | 1c8a5d7 | 2014-07-06 20:04:10 +0000 | [diff] [blame] | 19 | /* Both inline and __forceinline is OK. */ |
| 20 | inline void __forceinline pr8264(void) {} |
| 21 | __forceinline void inline pr8264_1(void) {} |
| 22 | void inline __forceinline pr8264_2(void) {} |
| 23 | void __forceinline inline pr8264_3(void) {} |
| 24 | /* But duplicate __forceinline causes warning. */ |
| 25 | void __forceinline __forceinline pr8264_4(void) { /* expected-warning{{duplicate '__forceinline' declaration specifier}} */ |
Serge Pavlov | 750db65 | 2013-11-13 06:57:53 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Aaron Ballman | 1c8a5d7 | 2014-07-06 20:04:10 +0000 | [diff] [blame] | 28 | _inline int foo99(void) { return 99; } |
Steve Naroff | f9c29d4 | 2008-12-25 14:41:26 +0000 | [diff] [blame] | 29 | |
Aaron Ballman | 1c8a5d7 | 2014-07-06 20:04:10 +0000 | [diff] [blame] | 30 | void test_ms_alignof_alias(void) { |
Douglas Gregor | 6cda071 | 2012-05-16 20:04:05 +0000 | [diff] [blame] | 31 | unsigned int s = _alignof(int); |
| 32 | s = __builtin_alignof(int); |
| 33 | } |
| 34 | |
Aaron Ballman | 1c8a5d7 | 2014-07-06 20:04:10 +0000 | [diff] [blame] | 35 | /* Charify extension. */ |
Chris Lattner | 3859c74 | 2009-12-23 19:15:27 +0000 | [diff] [blame] | 36 | #define FOO(x) #@x |
| 37 | char x = FOO(a); |
Andy Gibbs | 6f8cfccb | 2016-04-01 19:02:20 +0000 | [diff] [blame] | 38 | #define HASHAT #@ |
| 39 | #define MISSING_ARG(x) #@ |
| 40 | /* expected-error@-1 {{'#@' is not followed by a macro parameter}} */ |
Chris Lattner | 3859c74 | 2009-12-23 19:15:27 +0000 | [diff] [blame] | 41 | |
Douglas Gregor | 5692680 | 2010-07-16 15:18:19 +0000 | [diff] [blame] | 42 | typedef enum E { e1 }; |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 43 | |
Aaron Ballman | 1c8a5d7 | 2014-07-06 20:04:10 +0000 | [diff] [blame] | 44 | enum __declspec(deprecated) E2 { i, j, k }; /* expected-note {{'E2' has been explicitly marked deprecated here}} */ |
| 45 | __declspec(deprecated) enum E3 { a, b, c } e; /* expected-note {{'e' has been explicitly marked deprecated here}} */ |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 46 | |
Aaron Ballman | 1c8a5d7 | 2014-07-06 20:04:10 +0000 | [diff] [blame] | 47 | void deprecated_enum_test(void) { |
| 48 | /* Test to make sure the deprecated warning follows the right thing */ |
| 49 | enum E2 e1; /* expected-warning {{'E2' is deprecated}} */ |
| 50 | enum E3 e2; /* No warning expected, the deprecation follows the variable */ |
| 51 | enum E3 e3 = e; /* expected-warning {{'e' is deprecated}} */ |
Aaron Ballman | c42d838 | 2012-03-15 00:20:05 +0000 | [diff] [blame] | 52 | } |
Francois Pichet | d61f192 | 2010-10-11 12:00:10 +0000 | [diff] [blame] | 53 | |
Francois Pichet | c2bc5ac | 2010-10-11 12:59:39 +0000 | [diff] [blame] | 54 | /* Microsoft attribute tests */ |
Aaron Ballman | 478faed | 2012-06-19 22:09:27 +0000 | [diff] [blame] | 55 | [returnvalue:SA_Post( attr=1)] |
Francois Pichet | c2bc5ac | 2010-10-11 12:59:39 +0000 | [diff] [blame] | 56 | int foo1([SA_Post(attr=1)] void *param); |
| 57 | |
Saleem Abdulrasool | 425efcf | 2015-06-15 20:57:04 +0000 | [diff] [blame] | 58 | [unbalanced(attribute) /* expected-note {{to match this '['}} */ |
| 59 | void f(void); /* expected-error {{expected ']'}} */ |
| 60 | |
Aaron Ballman | 1c8a5d7 | 2014-07-06 20:04:10 +0000 | [diff] [blame] | 61 | void ms_intrinsics(int a) { |
Francois Pichet | d61f192 | 2010-10-11 12:00:10 +0000 | [diff] [blame] | 62 | __noop(); |
| 63 | __assume(a); |
Francois Pichet | 4ad2a27 | 2011-07-10 14:15:07 +0000 | [diff] [blame] | 64 | __debugbreak(); |
Francois Pichet | d61f192 | 2010-10-11 12:00:10 +0000 | [diff] [blame] | 65 | } |
Aaron Ballman | 478faed | 2012-06-19 22:09:27 +0000 | [diff] [blame] | 66 | |
Aaron Ballman | fdd783a | 2014-03-31 18:18:43 +0000 | [diff] [blame] | 67 | struct __declspec(frobble) S1 {}; /* expected-warning {{__declspec attribute 'frobble' is not supported}} */ |
Aaron Ballman | 478faed | 2012-06-19 22:09:27 +0000 | [diff] [blame] | 68 | struct __declspec(12) S2 {}; /* expected-error {{__declspec attributes must be an identifier or string literal}} */ |
| 69 | struct __declspec("testing") S3 {}; /* expected-warning {{__declspec attribute '"testing"' is not supported}} */ |
| 70 | |
Aaron Ballman | 95d5703 | 2014-04-14 16:44:26 +0000 | [diff] [blame] | 71 | /* declspecs with arguments cannot have an empty argument list, even if the |
| 72 | arguments are optional. */ |
Aaron Ballman | ef5d94c | 2014-04-15 00:36:39 +0000 | [diff] [blame] | 73 | __declspec(deprecated()) void dep_func_test(void); /* expected-error {{parentheses must be omitted if 'deprecated' attribute's argument list is empty}} */ |
Aaron Ballman | 95d5703 | 2014-04-14 16:44:26 +0000 | [diff] [blame] | 74 | __declspec(deprecated) void dep_func_test2(void); |
| 75 | __declspec(deprecated("")) void dep_func_test3(void); |
| 76 | |
Aaron Ballman | 478faed | 2012-06-19 22:09:27 +0000 | [diff] [blame] | 77 | /* Ensure multiple declspec attributes are supported */ |
| 78 | struct __declspec(align(8) deprecated) S4 {}; |
| 79 | |
| 80 | /* But multiple declspecs must still be legal */ |
Aaron Ballman | fdd783a | 2014-03-31 18:18:43 +0000 | [diff] [blame] | 81 | struct __declspec(deprecated frobble "testing") S5 {}; /* expected-warning {{__declspec attribute 'frobble' is not supported}} expected-warning {{__declspec attribute '"testing"' is not supported}} */ |
| 82 | struct __declspec(unknown(12) deprecated) S6 {}; /* expected-warning {{__declspec attribute 'unknown' is not supported}}*/ |
Aaron Ballman | 478faed | 2012-06-19 22:09:27 +0000 | [diff] [blame] | 83 | |
Aaron Ballman | 317a77f | 2013-05-22 23:25:32 +0000 | [diff] [blame] | 84 | int * __sptr psp; |
| 85 | int * __uptr pup; |
| 86 | /* Either ordering is acceptable */ |
| 87 | int * __ptr32 __sptr psp32; |
| 88 | int * __ptr32 __uptr pup32; |
| 89 | int * __sptr __ptr64 psp64; |
| 90 | int * __uptr __ptr64 pup64; |
| 91 | |
| 92 | /* Legal to have nested pointer attributes */ |
| 93 | int * __sptr * __ptr32 ppsp32; |
Nico Rieck | eaaae27 | 2014-12-04 23:31:08 +0000 | [diff] [blame] | 94 | |
| 95 | // Ignored type qualifiers after comma in declarator lists |
| 96 | typedef int ignored_quals_dummy1, const volatile __ptr32 __ptr64 __w64 __unaligned __sptr __uptr ignored_quals1; // expected-warning {{qualifiers after comma in declarator list are ignored}} |
| 97 | typedef void(*ignored_quals_dummy2)(), __fastcall ignored_quals2; // expected-warning {{qualifiers after comma in declarator list are ignored}} |
| 98 | typedef void(*ignored_quals_dummy3)(), __stdcall ignored_quals3; // expected-warning {{qualifiers after comma in declarator list are ignored}} |
| 99 | typedef void(*ignored_quals_dummy4)(), __thiscall ignored_quals4; // expected-warning {{qualifiers after comma in declarator list are ignored}} |
| 100 | typedef void(*ignored_quals_dummy5)(), __cdecl ignored_quals5; // expected-warning {{qualifiers after comma in declarator list are ignored}} |
| 101 | typedef void(*ignored_quals_dummy6)(), __vectorcall ignored_quals6; // expected-warning {{qualifiers after comma in declarator list are ignored}} |
David Majnemer | 936b411 | 2015-04-19 07:53:29 +0000 | [diff] [blame] | 102 | |
| 103 | __declspec(align(16)) struct align_before_key1 {}; |
| 104 | __declspec(align(16)) struct align_before_key2 {} align_before_key2_var; |
| 105 | __declspec(align(16)) struct align_before_key3 {} *align_before_key3_var; |
| 106 | _Static_assert(__alignof(struct align_before_key1) == 16, ""); |
| 107 | _Static_assert(__alignof(struct align_before_key2) == 16, ""); |
| 108 | _Static_assert(__alignof(struct align_before_key3) == 16, ""); |
David Majnemer | 6ac7dd1 | 2016-08-01 16:39:29 +0000 | [diff] [blame] | 109 | |
| 110 | void PR28782(int i) { |
| 111 | foo: |
| 112 | int n; |
| 113 | switch (i) { |
| 114 | case 0: |
| 115 | int m; |
| 116 | } |
| 117 | } |