MicrosoftExtensions.c 5.1 KB

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