blob: de933f9e5d60051da04e91341f3c5722bc40491a [file] [log] [blame]
Francois Pichet913b7bf2010-12-20 03:51:03 +00001// RUN: %clang_cc1 -triple i386-mingw32 -fsyntax-only -verify -fms-extensions -Wno-missing-declarations -x objective-c++ %s
Steve Naroff239f0732008-12-25 14:16:32 +00002__stdcall int func0();
3int __stdcall func();
4typedef int (__cdecl *tptr)();
5void (*__fastcall fastpfunc)();
Aaron Ballmanfc685ac2012-06-19 22:09:27 +00006struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) __declspec(novtable) IUnknown {}; /* expected-warning{{__declspec attribute 'novtable' is not supported}} */
Steve Naroff239f0732008-12-25 14:16:32 +00007extern __declspec(dllimport) void __stdcall VarR4FromDec();
8__declspec(deprecated) __declspec(deprecated) char * __cdecl ltoa( long _Val, char * _DstBuf, int _Radix);
Aaron Ballman3ce0de62013-05-04 16:58:37 +00009__declspec(safebuffers) __declspec(noalias) __declspec(restrict) void * __cdecl xxx( void * _Memory ); /* expected-warning{{__declspec attribute 'safebuffers' is not supported}} expected-warning{{__declspec attribute 'noalias' is not supported}} expected-warning{{__declspec attribute 'restrict' is not supported}} */
Steve Naroff86bc6cf2008-12-25 14:41:26 +000010typedef __w64 unsigned long ULONG_PTR, *PULONG_PTR;
Francois Pichet58fd97a2011-08-25 00:36:46 +000011
Steve Naroff86bc6cf2008-12-25 14:41:26 +000012void * __ptr64 PtrToPtr64(const void *p)
13{
John McCallc052dbb2012-05-22 21:28:12 +000014 return((void * __ptr64) (unsigned __int64) (ULONG_PTR)p );
Steve Naroff86bc6cf2008-12-25 14:41:26 +000015}
Francois Pichet58fd97a2011-08-25 00:36:46 +000016void * __ptr32 PtrToPtr32(const void *p)
17{
John McCallc052dbb2012-05-22 21:28:12 +000018 return((void * __ptr32) (unsigned __int32) (ULONG_PTR)p );
Francois Pichet58fd97a2011-08-25 00:36:46 +000019}
20
Chad Rosiere23fbf12012-12-05 23:08:09 +000021void __forceinline InterlockedBitTestAndSet (long *Base, long Bit)
22{
Richard Smithd03de6a2013-01-29 10:02:16 +000023 // FIXME: Re-enable this once MS inline asm stabilizes.
24#if 0
Chad Rosierc666cf42013-01-22 18:18:22 +000025 __asm {
Chad Rosiere23fbf12012-12-05 23:08:09 +000026 mov eax, Bit
27 mov ecx, Base
28 lock bts [ecx], eax
29 setc al
30 };
Richard Smithd03de6a2013-01-29 10:02:16 +000031#endif
Chad Rosiere23fbf12012-12-05 23:08:09 +000032}
Francois Pichet229ca4a2010-10-06 13:02:48 +000033_inline int foo99() { return 99; }
Steve Naroff86bc6cf2008-12-25 14:41:26 +000034
Douglas Gregorda8d8c22012-05-16 20:04:05 +000035void test_ms_alignof_alias() {
36 unsigned int s = _alignof(int);
37 s = __builtin_alignof(int);
38}
39
Steve Naroff47f52092009-01-06 19:34:12 +000040void *_alloca(int);
41
42void foo() {
Mike Stump1eb44332009-09-09 15:08:12 +000043 __declspec(align(16)) int *buffer = (int *)_alloca(9);
Steve Naroff47f52092009-01-06 19:34:12 +000044}
Douglas Gregor5a2f5d32009-01-10 00:48:18 +000045
46typedef bool (__stdcall __stdcall *blarg)(int);
Chris Lattner66335222009-12-23 19:15:27 +000047
Chris Lattner6229c8e2010-09-28 23:35:09 +000048void local_callconv()
49{
50 bool (__stdcall *p)(int);
51}
Chris Lattner66335222009-12-23 19:15:27 +000052
53// Charify extension.
54#define FOO(x) #@x
55char x = FOO(a);
56
Douglas Gregor0c99ec62010-07-16 15:18:19 +000057typedef enum E { e1 };
Francois Pichet01b7c302010-09-08 12:20:18 +000058
59
Eli Friedmanc3b23082012-08-08 21:52:41 +000060enum __declspec(deprecated) E2 { i, j, k }; // expected-note {{declared here}}
61__declspec(deprecated) enum E3 { a, b, c } e; // expected-note {{declared here}}
Francois Pichetd3d3be92010-12-20 01:41:49 +000062
Aaron Ballman0e3c9892012-03-15 00:20:05 +000063void deprecated_enum_test(void)
64{
65 // Test to make sure the deprecated warning follows the right thing
66 enum E2 e1; // expected-warning {{'E2' is deprecated}}
67 enum E3 e2; // No warning expected, the deprecation follows the variable
68 enum E3 e3 = e; // expected-warning {{'e' is deprecated}}
69}
Francois Pichetb2419462010-10-11 12:00:10 +000070
Francois Pichet334d47e2010-10-11 12:59:39 +000071/* Microsoft attribute tests */
72[repeatable][source_annotation_attribute( Parameter|ReturnValue )]
73struct SA_Post{ SA_Post(); int attr; };
74
Aaron Ballmanfc685ac2012-06-19 22:09:27 +000075[returnvalue:SA_Post( attr=1)]
Francois Pichet334d47e2010-10-11 12:59:39 +000076int foo1([SA_Post(attr=1)] void *param);
77
78
Francois Pichetb2419462010-10-11 12:00:10 +000079
80void ms_intrinsics(int a)
81{
82 __noop();
83 __assume(a);
Francois Pichet699f9b12011-07-10 14:15:07 +000084 __debugbreak();
Francois Pichetb2419462010-10-11 12:00:10 +000085}
Aaron Ballmanfc685ac2012-06-19 22:09:27 +000086
87struct __declspec(frobble) S1 {}; /* expected-warning {{unknown __declspec attribute 'frobble' ignored}} */
88struct __declspec(12) S2 {}; /* expected-error {{__declspec attributes must be an identifier or string literal}} */
89struct __declspec("testing") S3 {}; /* expected-warning {{__declspec attribute '"testing"' is not supported}} */
90
91/* Ensure multiple declspec attributes are supported */
92struct __declspec(align(8) deprecated) S4 {};
93
94/* But multiple declspecs must still be legal */
95struct __declspec(deprecated frobble "testing") S5 {}; /* expected-warning {{unknown __declspec attribute 'frobble' ignored}} expected-warning {{__declspec attribute '"testing"' is not supported}} */
96struct __declspec(unknown(12) deprecated) S6 {}; /* expected-warning {{unknown __declspec attribute 'unknown' ignored}}*/
97
98struct S7 {
99 int foo() { return 12; }
Eli Friedmanc3b23082012-08-08 21:52:41 +0000100 __declspec(property(get=foo) deprecated) int t; // expected-note {{declared here}}
Aaron Ballmanfc685ac2012-06-19 22:09:27 +0000101};
102
103/* Technically, this is legal (though it does nothing) */
104__declspec() void quux( void ) {
105 struct S7 s;
106 int i = s.t; /* expected-warning {{'t' is deprecated}} */
107}
Aaron Ballmanaa9df092013-05-22 23:25:32 +0000108
109int * __sptr psp;
110int * __uptr pup;
111/* Either ordering is acceptable */
112int * __ptr32 __sptr psp32;
113int * __ptr32 __uptr pup32;
114int * __sptr __ptr64 psp64;
115int * __uptr __ptr64 pup64;
116
117/* Legal to have nested pointer attributes */
118int * __sptr * __ptr32 ppsp32;