Arthur Eubanks | 51d7f64 | 2020-03-04 13:18:59 -0800 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value -Wno-pointer-to-int-cast -Wmicrosoft -verify -fms-extensions |
Chandler Carruth | a64aedb | 2010-10-06 06:50:05 +0000 | [diff] [blame] | 2 | |
| 3 | struct A |
| 4 | { |
| 5 | int a[]; /* expected-warning {{flexible array member 'a' in otherwise empty struct is a Microsoft extension}} */ |
| 6 | }; |
| 7 | |
David Majnemer | 3b568aa | 2016-07-04 00:24:59 +0000 | [diff] [blame] | 8 | struct PR28407 |
| 9 | { |
| 10 | int : 1; |
| 11 | int a[]; /* expected-warning {{flexible array member 'a' in otherwise empty struct is a Microsoft extension}} */ |
| 12 | }; |
| 13 | |
Chandler Carruth | a64aedb | 2010-10-06 06:50:05 +0000 | [diff] [blame] | 14 | struct C { |
| 15 | int l; |
| 16 | union { |
| 17 | int c1[]; /* expected-warning {{flexible array member 'c1' in a union is a Microsoft extension}} */ |
| 18 | char c2[]; /* expected-warning {{flexible array member 'c2' in a union is a Microsoft extension}} */ |
| 19 | }; |
| 20 | }; |
| 21 | |
| 22 | |
| 23 | struct D { |
| 24 | int l; |
| 25 | int D[]; |
| 26 | }; |
Francois Pichet | a310806 | 2010-10-18 15:01:13 +0000 | [diff] [blame] | 27 | |
Aaron Ballman | df8fe4c | 2013-11-24 21:35:16 +0000 | [diff] [blame] | 28 | struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown {}; /* expected-error {{'uuid' attribute is not supported in C}} */ |
Francois Pichet | 0c71f6c | 2010-11-23 06:07:27 +0000 | [diff] [blame] | 29 | |
Nico Weber | 05e1dad | 2016-09-03 03:25:22 +0000 | [diff] [blame] | 30 | [uuid("00000000-0000-0000-C000-000000000046")] struct IUnknown2 {}; /* expected-error {{'uuid' attribute is not supported in C}} */ |
| 31 | |
Francois Pichet | 0c71f6c | 2010-11-23 06:07:27 +0000 | [diff] [blame] | 32 | typedef struct notnested { |
| 33 | long bad1; |
| 34 | long bad2; |
| 35 | } NOTNESTED; |
| 36 | |
| 37 | |
| 38 | typedef struct nested1 { |
| 39 | long a; |
| 40 | struct notnested var1; |
| 41 | NOTNESTED var2; |
| 42 | } NESTED1; |
| 43 | |
| 44 | struct nested2 { |
| 45 | long b; |
| 46 | NESTED1; // expected-warning {{anonymous structs are a Microsoft extension}} |
| 47 | }; |
| 48 | |
David Majnemer | 36ef898 | 2014-08-11 18:33:59 +0000 | [diff] [blame] | 49 | struct nested2 PR20573 = { .a = 3 }; |
| 50 | |
David Majnemer | 8f0ed91 | 2014-08-11 07:29:54 +0000 | [diff] [blame] | 51 | struct nested3 { |
| 52 | long d; |
| 53 | struct nested4 { // expected-warning {{anonymous structs are a Microsoft extension}} |
| 54 | long e; |
| 55 | }; |
| 56 | union nested5 { // expected-warning {{anonymous unions are a Microsoft extension}} |
| 57 | long f; |
| 58 | }; |
| 59 | }; |
| 60 | |
| 61 | typedef union nested6 { |
| 62 | long f; |
| 63 | } NESTED6; |
| 64 | |
Francois Pichet | 0c71f6c | 2010-11-23 06:07:27 +0000 | [diff] [blame] | 65 | struct test { |
| 66 | int c; |
| 67 | struct nested2; // expected-warning {{anonymous structs are a Microsoft extension}} |
David Majnemer | 8f0ed91 | 2014-08-11 07:29:54 +0000 | [diff] [blame] | 68 | NESTED6; // expected-warning {{anonymous unions are a Microsoft extension}} |
Francois Pichet | 0c71f6c | 2010-11-23 06:07:27 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | void foo() |
| 72 | { |
| 73 | struct test var; |
| 74 | var.a; |
| 75 | var.b; |
| 76 | var.c; |
| 77 | var.bad1; // expected-error {{no member named 'bad1' in 'struct test'}} |
| 78 | var.bad2; // expected-error {{no member named 'bad2' in 'struct test'}} |
| 79 | } |
| 80 | |
Douglas Gregor | a1aec29 | 2011-02-22 20:32:04 +0000 | [diff] [blame] | 81 | // Enumeration types with a fixed underlying type. |
| 82 | const int seventeen = 17; |
| 83 | typedef int Int; |
| 84 | |
| 85 | struct X0 { |
| 86 | enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}} |
| 87 | enum E1 : seventeen; |
| 88 | }; |
| 89 | |
Douglas Gregor | 996a735b | 2011-02-22 21:42:31 +0000 | [diff] [blame] | 90 | enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}} |
Douglas Gregor | a1aec29 | 2011-02-22 20:32:04 +0000 | [diff] [blame] | 91 | SomeValue = 0x100000000 |
| 92 | }; |
Francois Pichet | 6f7289d | 2011-05-11 22:28:19 +0000 | [diff] [blame] | 93 | |
Francois Pichet | 6f7289d | 2011-05-11 22:28:19 +0000 | [diff] [blame] | 94 | void pointer_to_integral_type_conv(char* ptr) { |
Arthur Eubanks | 51d7f64 | 2020-03-04 13:18:59 -0800 | [diff] [blame] | 95 | char ch = (char)ptr; |
| 96 | short sh = (short)ptr; |
| 97 | ch = (char)ptr; |
| 98 | sh = (short)ptr; |
Hans Wennborg | 15439bc | 2013-06-06 09:16:36 +0000 | [diff] [blame] | 99 | |
Arthur Eubanks | 51d7f64 | 2020-03-04 13:18:59 -0800 | [diff] [blame] | 100 | // This is valid ISO C. |
| 101 | _Bool b = (_Bool)ptr; |
Nico Weber | f8bb3de | 2012-02-01 00:41:00 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Nico Weber | f8bb3de | 2012-02-01 00:41:00 +0000 | [diff] [blame] | 104 | typedef struct { |
| 105 | UNKNOWN u; // expected-error {{unknown type name 'UNKNOWN'}} |
| 106 | } AA; |
| 107 | |
| 108 | typedef struct { |
| 109 | AA; // expected-warning {{anonymous structs are a Microsoft extension}} |
| 110 | } BB; |
Aaron Ballman | 96e7c09 | 2012-02-23 01:19:31 +0000 | [diff] [blame] | 111 | |
David Majnemer | d8e366b | 2014-09-18 00:42:05 +0000 | [diff] [blame] | 112 | struct anon_fault { |
| 113 | struct undefined; // expected-warning {{anonymous structs are a Microsoft extension}} |
| 114 | // expected-error@-1 {{field has incomplete type 'struct undefined'}} |
| 115 | // expected-note@-2 {{forward declaration of 'struct undefined'}} |
| 116 | }; |
| 117 | |
| 118 | const int anon_falt_size = sizeof(struct anon_fault); |
| 119 | |
Ted Kremenek | b79ee57 | 2013-12-18 23:30:06 +0000 | [diff] [blame] | 120 | __declspec(deprecated("This is deprecated")) enum DE1 { one, two } e1; // expected-note {{'e1' has been explicitly marked deprecated here}} |
| 121 | struct __declspec(deprecated) DS1 { int i; float f; }; // expected-note {{'DS1' has been explicitly marked deprecated here}} |
Aaron Ballman | 96e7c09 | 2012-02-23 01:19:31 +0000 | [diff] [blame] | 122 | |
| 123 | #define MY_TEXT "This is also deprecated" |
Ted Kremenek | b79ee57 | 2013-12-18 23:30:06 +0000 | [diff] [blame] | 124 | __declspec(deprecated(MY_TEXT)) void Dfunc1( void ) {} // expected-note {{'Dfunc1' has been explicitly marked deprecated here}} |
Aaron Ballman | 96e7c09 | 2012-02-23 01:19:31 +0000 | [diff] [blame] | 125 | |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 126 | struct __declspec(deprecated(123)) DS2 {}; // expected-error {{'deprecated' attribute requires a string}} |
Aaron Ballman | 478faed4 | 2012-06-19 22:09:27 +0000 | [diff] [blame] | 127 | |
Aaron Ballman | 96e7c09 | 2012-02-23 01:19:31 +0000 | [diff] [blame] | 128 | void test( void ) { |
| 129 | e1 = one; // expected-warning {{'e1' is deprecated: This is deprecated}} |
| 130 | struct DS1 s = { 0 }; // expected-warning {{'DS1' is deprecated}} |
| 131 | Dfunc1(); // expected-warning {{'Dfunc1' is deprecated: This is also deprecated}} |
| 132 | |
| 133 | enum DE1 no; // no warning because E1 is not deprecated |
| 134 | } |
Aaron Ballman | 317a77f | 2013-05-22 23:25:32 +0000 | [diff] [blame] | 135 | |
| 136 | int __sptr wrong1; // expected-error {{'__sptr' attribute only applies to pointer arguments}} |
| 137 | // The modifier must follow the asterisk |
| 138 | int __sptr *wrong_psp; // expected-error {{'__sptr' attribute only applies to pointer arguments}} |
| 139 | int * __sptr __uptr wrong2; // expected-error {{'__sptr' and '__uptr' attributes are not compatible}} |
| 140 | int * __sptr __sptr wrong3; // expected-warning {{attribute '__sptr' is already applied}} |
| 141 | |
| 142 | // It is illegal to overload based on the type attribute. |
| 143 | void ptr_func(int * __ptr32 i) {} // expected-note {{previous definition is here}} |
| 144 | void ptr_func(int * __ptr64 i) {} // expected-error {{redefinition of 'ptr_func'}} |
| 145 | |
| 146 | // It is also illegal to overload based on the pointer type attribute. |
| 147 | void ptr_func2(int * __sptr __ptr32 i) {} // expected-note {{previous definition is here}} |
| 148 | void ptr_func2(int * __uptr __ptr32 i) {} // expected-error {{redefinition of 'ptr_func2'}} |
| 149 | |
Amy Huang | a85f5ef | 2019-10-24 16:34:25 -0700 | [diff] [blame] | 150 | // Check for warning when return types have the type attribute. |
| 151 | void *__ptr32 ptr_func3() { return 0; } // expected-note {{previous definition is here}} |
| 152 | void *__ptr64 ptr_func3() { return 0; } // expected-error {{redefinition of 'ptr_func3'}} |
| 153 | |
| 154 | // Test that __ptr32/__ptr64 can be passed as arguments with other address |
| 155 | // spaces. |
| 156 | void ptr_func4(int *i); |
| 157 | void ptr_func5(int *__ptr32 i); |
| 158 | void test_ptr_arguments() { |
| 159 | int *__ptr64 i64; |
| 160 | ptr_func4(i64); |
| 161 | ptr_func5(i64); |
| 162 | } |
| 163 | |
Aaron Ballman | 317a77f | 2013-05-22 23:25:32 +0000 | [diff] [blame] | 164 | int * __sptr __ptr32 __sptr wrong4; // expected-warning {{attribute '__sptr' is already applied}} |
| 165 | |
| 166 | __ptr32 int *wrong5; // expected-error {{'__ptr32' attribute only applies to pointer arguments}} |
| 167 | |
| 168 | int *wrong6 __ptr32; // expected-error {{expected ';' after top level declarator}} expected-warning {{declaration does not declare anything}} |
| 169 | |
| 170 | int * __ptr32 __ptr64 wrong7; // expected-error {{'__ptr32' and '__ptr64' attributes are not compatible}} |
| 171 | |
| 172 | int * __ptr32 __ptr32 wrong8; // expected-warning {{attribute '__ptr32' is already applied}} |
| 173 | |
| 174 | int *(__ptr32 __sptr wrong9); // expected-error {{'__sptr' attribute only applies to pointer arguments}} // expected-error {{'__ptr32' attribute only applies to pointer arguments}} |
| 175 | |
| 176 | typedef int *T; |
| 177 | T __ptr32 wrong10; // expected-error {{'__ptr32' attribute only applies to pointer arguments}} |
Reid Kleckner | 597e81d | 2014-03-26 15:38:33 +0000 | [diff] [blame] | 178 | |
| 179 | typedef char *my_va_list; |
Reid Kleckner | 55e3cec6 | 2014-03-26 22:52:23 +0000 | [diff] [blame] | 180 | void __va_start(my_va_list *ap, ...); // expected-note {{passing argument to parameter 'ap' here}} |
Reid Kleckner | 597e81d | 2014-03-26 15:38:33 +0000 | [diff] [blame] | 181 | void vmyprintf(const char *f, my_va_list ap); |
| 182 | void myprintf(const char *f, ...) { |
| 183 | my_va_list ap; |
| 184 | if (1) { |
| 185 | __va_start(&ap, f); |
| 186 | vmyprintf(f, ap); |
| 187 | ap = 0; |
| 188 | } else { |
| 189 | __va_start(ap, f); // expected-warning {{incompatible pointer types passing 'my_va_list'}} |
| 190 | } |
| 191 | } |
Andrey Bokhanko | 45d4132 | 2016-05-11 18:38:21 +0000 | [diff] [blame] | 192 | |
| 193 | // __unaligned handling |
| 194 | void test_unaligned() { |
| 195 | __unaligned int *p1 = 0; |
| 196 | int *p2 = p1; // expected-warning {{initializing 'int *' with an expression of type '__unaligned int *' discards qualifiers}} |
| 197 | __unaligned int *p3 = p2; |
| 198 | } |
| 199 | |
Andrey Bokhanko | 67a4186 | 2016-05-26 10:06:01 +0000 | [diff] [blame] | 200 | void test_unaligned2(int x[__unaligned 4]) {} |
| 201 | |