blob: 2af6c421bcce294b91a4dc3ff439c1616d18529e [file] [log] [blame]
Aaron Ballman1c8a5d72014-07-06 20:04:10 +00001// RUN: %clang_cc1 -triple i386-mingw32 -fsyntax-only -Wno-missing-declarations -verify -fms-extensions %s
2__stdcall int func0(void);
3int __stdcall func(void);
4typedef int (__cdecl *tptr)(void);
5void (*__fastcall fastpfunc)(void);
6extern __declspec(dllimport) void __stdcall VarR4FromDec(void);
Steve Naroff44ac7772008-12-25 14:16:32 +00007__declspec(deprecated) __declspec(deprecated) char * __cdecl ltoa( long _Val, char * _DstBuf, int _Radix);
David Majnemer1bf0f8e2015-07-20 22:51:52 +00008__declspec(safebuffers) __declspec(noalias) __declspec(restrict) void * __cdecl xxx(void *_Memory); /* expected-warning{{__declspec attribute 'safebuffers' is not supported}} */
Steve Narofff9c29d42008-12-25 14:41:26 +00009typedef __w64 unsigned long ULONG_PTR, *PULONG_PTR;
Francois Pichetf2fb4112011-08-25 00:36:46 +000010
Aaron Ballman1c8a5d72014-07-06 20:04:10 +000011void * __ptr64 PtrToPtr64(const void *p) {
John McCall8d32c052012-05-22 21:28:12 +000012 return((void * __ptr64) (unsigned __int64) (ULONG_PTR)p );
Steve Narofff9c29d42008-12-25 14:41:26 +000013}
Aaron Ballman1c8a5d72014-07-06 20:04:10 +000014
15void * __ptr32 PtrToPtr32(const void *p) {
John McCall8d32c052012-05-22 21:28:12 +000016 return((void * __ptr32) (unsigned __int32) (ULONG_PTR)p );
Francois Pichetf2fb4112011-08-25 00:36:46 +000017}
18
Aaron Ballman1c8a5d72014-07-06 20:04:10 +000019/* Both inline and __forceinline is OK. */
20inline void __forceinline pr8264(void) {}
21__forceinline void inline pr8264_1(void) {}
22void inline __forceinline pr8264_2(void) {}
23void __forceinline inline pr8264_3(void) {}
24/* But duplicate __forceinline causes warning. */
25void __forceinline __forceinline pr8264_4(void) { /* expected-warning{{duplicate '__forceinline' declaration specifier}} */
Serge Pavlov750db652013-11-13 06:57:53 +000026}
27
Aaron Ballman1c8a5d72014-07-06 20:04:10 +000028_inline int foo99(void) { return 99; }
Steve Narofff9c29d42008-12-25 14:41:26 +000029
Aaron Ballman1c8a5d72014-07-06 20:04:10 +000030void test_ms_alignof_alias(void) {
Douglas Gregor6cda0712012-05-16 20:04:05 +000031 unsigned int s = _alignof(int);
32 s = __builtin_alignof(int);
33}
34
Aaron Ballman1c8a5d72014-07-06 20:04:10 +000035/* Charify extension. */
Chris Lattner3859c742009-12-23 19:15:27 +000036#define FOO(x) #@x
37char x = FOO(a);
Andy Gibbs6f8cfccb2016-04-01 19:02:20 +000038#define HASHAT #@
39#define MISSING_ARG(x) #@
40/* expected-error@-1 {{'#@' is not followed by a macro parameter}} */
Chris Lattner3859c742009-12-23 19:15:27 +000041
Douglas Gregor56926802010-07-16 15:18:19 +000042typedef enum E { e1 };
Francois Pichet9f4f2072010-09-08 12:20:18 +000043
Aaron Ballman1c8a5d72014-07-06 20:04:10 +000044enum __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 Pichet9f4f2072010-09-08 12:20:18 +000046
Aaron Ballman1c8a5d72014-07-06 20:04:10 +000047void 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 Ballmanc42d8382012-03-15 00:20:05 +000052}
Francois Pichetd61f1922010-10-11 12:00:10 +000053
Francois Pichetc2bc5ac2010-10-11 12:59:39 +000054/* Microsoft attribute tests */
Aaron Ballman478faed2012-06-19 22:09:27 +000055[returnvalue:SA_Post( attr=1)]
Francois Pichetc2bc5ac2010-10-11 12:59:39 +000056int foo1([SA_Post(attr=1)] void *param);
57
Saleem Abdulrasool425efcf2015-06-15 20:57:04 +000058[unbalanced(attribute) /* expected-note {{to match this '['}} */
59void f(void); /* expected-error {{expected ']'}} */
60
Aaron Ballman1c8a5d72014-07-06 20:04:10 +000061void ms_intrinsics(int a) {
Francois Pichetd61f1922010-10-11 12:00:10 +000062 __noop();
63 __assume(a);
Francois Pichet4ad2a272011-07-10 14:15:07 +000064 __debugbreak();
Francois Pichetd61f1922010-10-11 12:00:10 +000065}
Aaron Ballman478faed2012-06-19 22:09:27 +000066
Aaron Ballmanfdd783a2014-03-31 18:18:43 +000067struct __declspec(frobble) S1 {}; /* expected-warning {{__declspec attribute 'frobble' is not supported}} */
Aaron Ballman478faed2012-06-19 22:09:27 +000068struct __declspec(12) S2 {}; /* expected-error {{__declspec attributes must be an identifier or string literal}} */
69struct __declspec("testing") S3 {}; /* expected-warning {{__declspec attribute '"testing"' is not supported}} */
70
Aaron Ballman95d57032014-04-14 16:44:26 +000071/* declspecs with arguments cannot have an empty argument list, even if the
72 arguments are optional. */
Aaron Ballmanef5d94c2014-04-15 00:36:39 +000073__declspec(deprecated()) void dep_func_test(void); /* expected-error {{parentheses must be omitted if 'deprecated' attribute's argument list is empty}} */
Aaron Ballman95d57032014-04-14 16:44:26 +000074__declspec(deprecated) void dep_func_test2(void);
75__declspec(deprecated("")) void dep_func_test3(void);
76
Aaron Ballman478faed2012-06-19 22:09:27 +000077/* Ensure multiple declspec attributes are supported */
78struct __declspec(align(8) deprecated) S4 {};
79
80/* But multiple declspecs must still be legal */
Aaron Ballmanfdd783a2014-03-31 18:18:43 +000081struct __declspec(deprecated frobble "testing") S5 {}; /* expected-warning {{__declspec attribute 'frobble' is not supported}} expected-warning {{__declspec attribute '"testing"' is not supported}} */
82struct __declspec(unknown(12) deprecated) S6 {}; /* expected-warning {{__declspec attribute 'unknown' is not supported}}*/
Aaron Ballman478faed2012-06-19 22:09:27 +000083
Aaron Ballman317a77f2013-05-22 23:25:32 +000084int * __sptr psp;
85int * __uptr pup;
86/* Either ordering is acceptable */
87int * __ptr32 __sptr psp32;
88int * __ptr32 __uptr pup32;
89int * __sptr __ptr64 psp64;
90int * __uptr __ptr64 pup64;
91
92/* Legal to have nested pointer attributes */
93int * __sptr * __ptr32 ppsp32;
Nico Rieckeaaae272014-12-04 23:31:08 +000094
95// Ignored type qualifiers after comma in declarator lists
96typedef int ignored_quals_dummy1, const volatile __ptr32 __ptr64 __w64 __unaligned __sptr __uptr ignored_quals1; // expected-warning {{qualifiers after comma in declarator list are ignored}}
97typedef void(*ignored_quals_dummy2)(), __fastcall ignored_quals2; // expected-warning {{qualifiers after comma in declarator list are ignored}}
98typedef void(*ignored_quals_dummy3)(), __stdcall ignored_quals3; // expected-warning {{qualifiers after comma in declarator list are ignored}}
99typedef void(*ignored_quals_dummy4)(), __thiscall ignored_quals4; // expected-warning {{qualifiers after comma in declarator list are ignored}}
100typedef void(*ignored_quals_dummy5)(), __cdecl ignored_quals5; // expected-warning {{qualifiers after comma in declarator list are ignored}}
101typedef void(*ignored_quals_dummy6)(), __vectorcall ignored_quals6; // expected-warning {{qualifiers after comma in declarator list are ignored}}
David Majnemer936b4112015-04-19 07:53:29 +0000102
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 Majnemer6ac7dd12016-08-01 16:39:29 +0000109
110void PR28782(int i) {
111foo:
112 int n;
113 switch (i) {
114 case 0:
115 int m;
116 }
117}