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