xref: /minix3/external/bsd/llvm/dist/clang/test/Parser/MicrosoftExtensions.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i386-mingw32 -fsyntax-only -verify -fms-extensions  -Wno-missing-declarations -x objective-c++ %s
2*f4a2713aSLionel Sambuc __stdcall int func0();
3*f4a2713aSLionel Sambuc int __stdcall func();
4*f4a2713aSLionel Sambuc typedef int (__cdecl *tptr)();
5*f4a2713aSLionel Sambuc void (*__fastcall fastpfunc)();
6*f4a2713aSLionel Sambuc struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) __declspec(novtable) IUnknown {}; /* expected-warning{{__declspec attribute 'novtable' is not supported}} */
7*f4a2713aSLionel Sambuc extern __declspec(dllimport) void __stdcall VarR4FromDec();
8*f4a2713aSLionel Sambuc __declspec(deprecated) __declspec(deprecated) char * __cdecl ltoa( long _Val, char * _DstBuf, int _Radix);
9*f4a2713aSLionel Sambuc __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}} */
10*f4a2713aSLionel Sambuc typedef __w64 unsigned long ULONG_PTR, *PULONG_PTR;
11*f4a2713aSLionel Sambuc 
12*f4a2713aSLionel Sambuc void * __ptr64 PtrToPtr64(const void *p)
13*f4a2713aSLionel Sambuc {
14*f4a2713aSLionel Sambuc   return((void * __ptr64) (unsigned __int64) (ULONG_PTR)p );
15*f4a2713aSLionel Sambuc }
16*f4a2713aSLionel Sambuc void * __ptr32 PtrToPtr32(const void *p)
17*f4a2713aSLionel Sambuc {
18*f4a2713aSLionel Sambuc   return((void * __ptr32) (unsigned __int32) (ULONG_PTR)p );
19*f4a2713aSLionel Sambuc }
20*f4a2713aSLionel Sambuc 
21*f4a2713aSLionel Sambuc void __forceinline InterlockedBitTestAndSet (long *Base, long Bit)
22*f4a2713aSLionel Sambuc {
23*f4a2713aSLionel Sambuc   // FIXME: Re-enable this once MS inline asm stabilizes.
24*f4a2713aSLionel Sambuc #if 0
25*f4a2713aSLionel Sambuc   __asm {
26*f4a2713aSLionel Sambuc     mov eax, Bit
27*f4a2713aSLionel Sambuc     mov ecx, Base
28*f4a2713aSLionel Sambuc     lock bts [ecx], eax
29*f4a2713aSLionel Sambuc     setc al
30*f4a2713aSLionel Sambuc   };
31*f4a2713aSLionel Sambuc #endif
32*f4a2713aSLionel Sambuc }
33*f4a2713aSLionel Sambuc 
34*f4a2713aSLionel Sambuc // Both inline and __forceinline is OK.
35*f4a2713aSLionel Sambuc inline void __forceinline pr8264() {
36*f4a2713aSLionel Sambuc }
37*f4a2713aSLionel Sambuc __forceinline void inline pr8264_1() {
38*f4a2713aSLionel Sambuc }
39*f4a2713aSLionel Sambuc void inline __forceinline pr8264_2() {
40*f4a2713aSLionel Sambuc }
41*f4a2713aSLionel Sambuc void __forceinline inline pr8264_3() {
42*f4a2713aSLionel Sambuc }
43*f4a2713aSLionel Sambuc // But duplicate __forceinline causes warning.
44*f4a2713aSLionel Sambuc void __forceinline __forceinline pr8264_4() {  // expected-warning{{duplicate '__forceinline' declaration specifier}}
45*f4a2713aSLionel Sambuc }
46*f4a2713aSLionel Sambuc 
47*f4a2713aSLionel Sambuc _inline int foo99() { return 99; }
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc void test_ms_alignof_alias() {
50*f4a2713aSLionel Sambuc   unsigned int s = _alignof(int);
51*f4a2713aSLionel Sambuc   s = __builtin_alignof(int);
52*f4a2713aSLionel Sambuc }
53*f4a2713aSLionel Sambuc 
54*f4a2713aSLionel Sambuc void *_alloca(int);
55*f4a2713aSLionel Sambuc 
56*f4a2713aSLionel Sambuc void foo() {
57*f4a2713aSLionel Sambuc   __declspec(align(16)) int *buffer = (int *)_alloca(9);
58*f4a2713aSLionel Sambuc }
59*f4a2713aSLionel Sambuc 
60*f4a2713aSLionel Sambuc typedef bool (__stdcall __stdcall *blarg)(int);
61*f4a2713aSLionel Sambuc 
62*f4a2713aSLionel Sambuc void local_callconv()
63*f4a2713aSLionel Sambuc {
64*f4a2713aSLionel Sambuc   bool (__stdcall *p)(int);
65*f4a2713aSLionel Sambuc }
66*f4a2713aSLionel Sambuc 
67*f4a2713aSLionel Sambuc // Charify extension.
68*f4a2713aSLionel Sambuc #define FOO(x) #@x
69*f4a2713aSLionel Sambuc char x = FOO(a);
70*f4a2713aSLionel Sambuc 
71*f4a2713aSLionel Sambuc typedef enum E { e1 };
72*f4a2713aSLionel Sambuc 
73*f4a2713aSLionel Sambuc 
74*f4a2713aSLionel Sambuc enum __declspec(deprecated) E2 { i, j, k }; // expected-note {{declared here}}
75*f4a2713aSLionel Sambuc __declspec(deprecated) enum E3 { a, b, c } e; // expected-note {{declared here}}
76*f4a2713aSLionel Sambuc 
77*f4a2713aSLionel Sambuc void deprecated_enum_test(void)
78*f4a2713aSLionel Sambuc {
79*f4a2713aSLionel Sambuc   // Test to make sure the deprecated warning follows the right thing
80*f4a2713aSLionel Sambuc   enum E2 e1;  // expected-warning {{'E2' is deprecated}}
81*f4a2713aSLionel Sambuc   enum E3 e2; // No warning expected, the deprecation follows the variable
82*f4a2713aSLionel Sambuc   enum E3 e3 = e;  // expected-warning {{'e' is deprecated}}
83*f4a2713aSLionel Sambuc }
84*f4a2713aSLionel Sambuc 
85*f4a2713aSLionel Sambuc /* Microsoft attribute tests */
86*f4a2713aSLionel Sambuc [repeatable][source_annotation_attribute( Parameter|ReturnValue )]
87*f4a2713aSLionel Sambuc struct SA_Post{ SA_Post(); int attr; };
88*f4a2713aSLionel Sambuc 
89*f4a2713aSLionel Sambuc [returnvalue:SA_Post( attr=1)]
90*f4a2713aSLionel Sambuc int foo1([SA_Post(attr=1)] void *param);
91*f4a2713aSLionel Sambuc 
92*f4a2713aSLionel Sambuc 
93*f4a2713aSLionel Sambuc 
94*f4a2713aSLionel Sambuc void ms_intrinsics(int a)
95*f4a2713aSLionel Sambuc {
96*f4a2713aSLionel Sambuc   __noop();
97*f4a2713aSLionel Sambuc   __assume(a);
98*f4a2713aSLionel Sambuc   __debugbreak();
99*f4a2713aSLionel Sambuc }
100*f4a2713aSLionel Sambuc 
101*f4a2713aSLionel Sambuc struct __declspec(frobble) S1 {};	/* expected-warning {{unknown __declspec attribute 'frobble' ignored}} */
102*f4a2713aSLionel Sambuc struct __declspec(12) S2 {};	/* expected-error {{__declspec attributes must be an identifier or string literal}} */
103*f4a2713aSLionel Sambuc struct __declspec("testing") S3 {}; /* expected-warning {{__declspec attribute '"testing"' is not supported}} */
104*f4a2713aSLionel Sambuc 
105*f4a2713aSLionel Sambuc /* Ensure multiple declspec attributes are supported */
106*f4a2713aSLionel Sambuc struct __declspec(align(8) deprecated) S4 {};
107*f4a2713aSLionel Sambuc 
108*f4a2713aSLionel Sambuc /* But multiple declspecs must still be legal */
109*f4a2713aSLionel Sambuc struct __declspec(deprecated frobble "testing") S5 {};  /* expected-warning {{unknown __declspec attribute 'frobble' ignored}} expected-warning {{__declspec attribute '"testing"' is not supported}} */
110*f4a2713aSLionel Sambuc struct __declspec(unknown(12) deprecated) S6 {};	/* expected-warning {{unknown __declspec attribute 'unknown' ignored}}*/
111*f4a2713aSLionel Sambuc 
112*f4a2713aSLionel Sambuc struct S7 {
113*f4a2713aSLionel Sambuc 	int foo() { return 12; }
114*f4a2713aSLionel Sambuc 	__declspec(property(get=foo) deprecated) int t; // expected-note {{declared here}}
115*f4a2713aSLionel Sambuc };
116*f4a2713aSLionel Sambuc 
117*f4a2713aSLionel Sambuc /* Technically, this is legal (though it does nothing) */
118*f4a2713aSLionel Sambuc __declspec() void quux( void ) {
119*f4a2713aSLionel Sambuc   struct S7 s;
120*f4a2713aSLionel Sambuc   int i = s.t;	/* expected-warning {{'t' is deprecated}} */
121*f4a2713aSLionel Sambuc }
122*f4a2713aSLionel Sambuc 
123*f4a2713aSLionel Sambuc int * __sptr psp;
124*f4a2713aSLionel Sambuc int * __uptr pup;
125*f4a2713aSLionel Sambuc /* Either ordering is acceptable */
126*f4a2713aSLionel Sambuc int * __ptr32 __sptr psp32;
127*f4a2713aSLionel Sambuc int * __ptr32 __uptr pup32;
128*f4a2713aSLionel Sambuc int * __sptr __ptr64 psp64;
129*f4a2713aSLionel Sambuc int * __uptr __ptr64 pup64;
130*f4a2713aSLionel Sambuc 
131*f4a2713aSLionel Sambuc /* Legal to have nested pointer attributes */
132*f4a2713aSLionel Sambuc int * __sptr * __ptr32 ppsp32;
133