xref: /minix3/external/bsd/llvm/dist/clang/test/Parser/MicrosoftExtensions.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple i386-mingw32 -fsyntax-only -Wno-missing-declarations -verify -fms-extensions  %s
2*0a6a1f1dSLionel Sambuc __stdcall int func0(void);
3*0a6a1f1dSLionel Sambuc int __stdcall func(void);
4*0a6a1f1dSLionel Sambuc typedef int (__cdecl *tptr)(void);
5*0a6a1f1dSLionel Sambuc void (*__fastcall fastpfunc)(void);
6*0a6a1f1dSLionel Sambuc extern __declspec(dllimport) void __stdcall VarR4FromDec(void);
7f4a2713aSLionel Sambuc __declspec(deprecated) __declspec(deprecated) char * __cdecl ltoa( long _Val, char * _DstBuf, int _Radix);
8f4a2713aSLionel 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}} */
9f4a2713aSLionel Sambuc typedef __w64 unsigned long ULONG_PTR, *PULONG_PTR;
10f4a2713aSLionel Sambuc 
PtrToPtr64(const void * p)11*0a6a1f1dSLionel Sambuc void * __ptr64 PtrToPtr64(const void *p) {
12f4a2713aSLionel Sambuc   return((void * __ptr64) (unsigned __int64) (ULONG_PTR)p );
13f4a2713aSLionel Sambuc }
14*0a6a1f1dSLionel Sambuc 
PtrToPtr32(const void * p)15*0a6a1f1dSLionel Sambuc void * __ptr32 PtrToPtr32(const void *p) {
16f4a2713aSLionel Sambuc   return((void * __ptr32) (unsigned __int32) (ULONG_PTR)p );
17f4a2713aSLionel Sambuc }
18f4a2713aSLionel Sambuc 
19*0a6a1f1dSLionel Sambuc /* Both inline and __forceinline is OK. */
pr8264(void)20*0a6a1f1dSLionel Sambuc inline void __forceinline pr8264(void) {}
pr8264_1(void)21*0a6a1f1dSLionel Sambuc __forceinline void inline pr8264_1(void) {}
pr8264_2(void)22*0a6a1f1dSLionel Sambuc void inline __forceinline pr8264_2(void) {}
pr8264_3(void)23*0a6a1f1dSLionel Sambuc void __forceinline inline pr8264_3(void) {}
24*0a6a1f1dSLionel Sambuc /* But duplicate __forceinline causes warning. */
pr8264_4(void)25*0a6a1f1dSLionel Sambuc void __forceinline __forceinline pr8264_4(void) {  /* expected-warning{{duplicate '__forceinline' declaration specifier}} */
26f4a2713aSLionel Sambuc }
27f4a2713aSLionel Sambuc 
foo99(void)28*0a6a1f1dSLionel Sambuc _inline int foo99(void) { return 99; }
29f4a2713aSLionel Sambuc 
test_ms_alignof_alias(void)30*0a6a1f1dSLionel Sambuc void test_ms_alignof_alias(void) {
31f4a2713aSLionel Sambuc   unsigned int s = _alignof(int);
32f4a2713aSLionel Sambuc   s = __builtin_alignof(int);
33f4a2713aSLionel Sambuc }
34f4a2713aSLionel Sambuc 
35*0a6a1f1dSLionel Sambuc /* Charify extension. */
36f4a2713aSLionel Sambuc #define FOO(x) #@x
37f4a2713aSLionel Sambuc char x = FOO(a);
38f4a2713aSLionel Sambuc 
39f4a2713aSLionel Sambuc typedef enum E { e1 };
40f4a2713aSLionel Sambuc 
41*0a6a1f1dSLionel Sambuc enum __declspec(deprecated) E2 { i, j, k }; /* expected-note {{'E2' has been explicitly marked deprecated here}} */
42*0a6a1f1dSLionel Sambuc __declspec(deprecated) enum E3 { a, b, c } e; /* expected-note {{'e' has been explicitly marked deprecated here}} */
43f4a2713aSLionel Sambuc 
deprecated_enum_test(void)44*0a6a1f1dSLionel Sambuc void deprecated_enum_test(void) {
45*0a6a1f1dSLionel Sambuc   /* Test to make sure the deprecated warning follows the right thing */
46*0a6a1f1dSLionel Sambuc   enum E2 e1;  /* expected-warning {{'E2' is deprecated}} */
47*0a6a1f1dSLionel Sambuc   enum E3 e2; /* No warning expected, the deprecation follows the variable */
48*0a6a1f1dSLionel Sambuc   enum E3 e3 = e;  /* expected-warning {{'e' is deprecated}} */
49f4a2713aSLionel Sambuc }
50f4a2713aSLionel Sambuc 
51f4a2713aSLionel Sambuc /* Microsoft attribute tests */
52f4a2713aSLionel Sambuc [returnvalue:SA_Post( attr=1)]
53f4a2713aSLionel Sambuc int foo1([SA_Post(attr=1)] void *param);
54f4a2713aSLionel Sambuc 
ms_intrinsics(int a)55*0a6a1f1dSLionel Sambuc void ms_intrinsics(int a) {
56f4a2713aSLionel Sambuc   __noop();
57f4a2713aSLionel Sambuc   __assume(a);
58f4a2713aSLionel Sambuc   __debugbreak();
59f4a2713aSLionel Sambuc }
60f4a2713aSLionel Sambuc 
61*0a6a1f1dSLionel Sambuc struct __declspec(frobble) S1 {};	/* expected-warning {{__declspec attribute 'frobble' is not supported}} */
62f4a2713aSLionel Sambuc struct __declspec(12) S2 {};	/* expected-error {{__declspec attributes must be an identifier or string literal}} */
63f4a2713aSLionel Sambuc struct __declspec("testing") S3 {}; /* expected-warning {{__declspec attribute '"testing"' is not supported}} */
64f4a2713aSLionel Sambuc 
65*0a6a1f1dSLionel Sambuc /* declspecs with arguments cannot have an empty argument list, even if the
66*0a6a1f1dSLionel Sambuc    arguments are optional. */
67*0a6a1f1dSLionel Sambuc __declspec(deprecated()) void dep_func_test(void); /* expected-error {{parentheses must be omitted if 'deprecated' attribute's argument list is empty}} */
68*0a6a1f1dSLionel Sambuc __declspec(deprecated) void dep_func_test2(void);
69*0a6a1f1dSLionel Sambuc __declspec(deprecated("")) void dep_func_test3(void);
70*0a6a1f1dSLionel Sambuc 
71f4a2713aSLionel Sambuc /* Ensure multiple declspec attributes are supported */
72f4a2713aSLionel Sambuc struct __declspec(align(8) deprecated) S4 {};
73f4a2713aSLionel Sambuc 
74f4a2713aSLionel Sambuc /* But multiple declspecs must still be legal */
75*0a6a1f1dSLionel Sambuc struct __declspec(deprecated frobble "testing") S5 {};  /* expected-warning {{__declspec attribute 'frobble' is not supported}} expected-warning {{__declspec attribute '"testing"' is not supported}} */
76*0a6a1f1dSLionel Sambuc struct __declspec(unknown(12) deprecated) S6 {};	/* expected-warning {{__declspec attribute 'unknown' is not supported}}*/
77f4a2713aSLionel Sambuc 
78f4a2713aSLionel Sambuc int * __sptr psp;
79f4a2713aSLionel Sambuc int * __uptr pup;
80f4a2713aSLionel Sambuc /* Either ordering is acceptable */
81f4a2713aSLionel Sambuc int * __ptr32 __sptr psp32;
82f4a2713aSLionel Sambuc int * __ptr32 __uptr pup32;
83f4a2713aSLionel Sambuc int * __sptr __ptr64 psp64;
84f4a2713aSLionel Sambuc int * __uptr __ptr64 pup64;
85f4a2713aSLionel Sambuc 
86f4a2713aSLionel Sambuc /* Legal to have nested pointer attributes */
87f4a2713aSLionel Sambuc int * __sptr * __ptr32 ppsp32;
88*0a6a1f1dSLionel Sambuc 
89*0a6a1f1dSLionel Sambuc // Ignored type qualifiers after comma in declarator lists
90*0a6a1f1dSLionel Sambuc 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}}
91*0a6a1f1dSLionel Sambuc typedef void(*ignored_quals_dummy2)(), __fastcall ignored_quals2; // expected-warning {{qualifiers after comma in declarator list are ignored}}
92*0a6a1f1dSLionel Sambuc typedef void(*ignored_quals_dummy3)(), __stdcall ignored_quals3; // expected-warning {{qualifiers after comma in declarator list are ignored}}
93*0a6a1f1dSLionel Sambuc typedef void(*ignored_quals_dummy4)(), __thiscall ignored_quals4; // expected-warning {{qualifiers after comma in declarator list are ignored}}
94*0a6a1f1dSLionel Sambuc typedef void(*ignored_quals_dummy5)(), __cdecl ignored_quals5; // expected-warning {{qualifiers after comma in declarator list are ignored}}
95*0a6a1f1dSLionel Sambuc typedef void(*ignored_quals_dummy6)(), __vectorcall ignored_quals6; // expected-warning {{qualifiers after comma in declarator list are ignored}}
96