2020-03-04 13:18:59 -08:00
// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value -Wno-pointer-to-int-cast -Wmicrosoft -verify -fms-extensions
2010-10-06 06:50:05 +00:00
struct A
{
int a [ ] ; /* expected-warning {{flexible array member 'a' in otherwise empty struct is a Microsoft extension}} */
} ;
2016-07-04 00:24:59 +00:00
struct PR28407
{
int : 1 ;
int a [ ] ; /* expected-warning {{flexible array member 'a' in otherwise empty struct is a Microsoft extension}} */
} ;
2010-10-06 06:50:05 +00:00
struct C {
int l ;
union {
2023-05-03 09:24:52 -04:00
int c1 [ ] ; /* expected-warning {{flexible array member 'c1' in a union is a Microsoft extension}} */
char c2 [ ] ; /* expected-warning {{flexible array member 'c2' in a union is a Microsoft extension}} */
2010-10-06 06:50:05 +00:00
} ;
} ;
struct D {
int l ;
int D [ ] ;
} ;
2010-10-18 15:01:13 +00:00
2013-11-24 21:35:16 +00:00
struct __declspec ( uuid ( " 00000000-0000-0000-C000-000000000046 " ) ) IUnknown { } ; /* expected-error {{'uuid' attribute is not supported in C}} */
2010-11-23 06:07:27 +00:00
2016-09-03 03:25:22 +00:00
[ uuid ( " 00000000-0000-0000-C000-000000000046 " ) ] struct IUnknown2 { } ; /* expected-error {{'uuid' attribute is not supported in C}} */
2010-11-23 06:07:27 +00:00
typedef struct notnested {
long bad1 ;
long bad2 ;
} NOTNESTED ;
typedef struct nested1 {
long a ;
struct notnested var1 ;
NOTNESTED var2 ;
} NESTED1 ;
struct nested2 {
long b ;
NESTED1 ; // expected-warning {{anonymous structs are a Microsoft extension}}
} ;
2014-08-11 18:33:59 +00:00
struct nested2 PR20573 = { . a = 3 } ;
2014-08-11 07:29:54 +00:00
struct nested3 {
long d ;
struct nested4 { // expected-warning {{anonymous structs are a Microsoft extension}}
long e ;
} ;
union nested5 { // expected-warning {{anonymous unions are a Microsoft extension}}
long f ;
} ;
} ;
typedef union nested6 {
long f ;
} NESTED6 ;
2010-11-23 06:07:27 +00:00
struct test {
int c ;
struct nested2 ; // expected-warning {{anonymous structs are a Microsoft extension}}
2014-08-11 07:29:54 +00:00
NESTED6 ; // expected-warning {{anonymous unions are a Microsoft extension}}
2010-11-23 06:07:27 +00:00
} ;
2022-02-03 16:39:21 -05:00
void foo ( void )
2010-11-23 06:07:27 +00:00
{
struct test var ;
var . a ;
var . b ;
var . c ;
var . bad1 ; // expected-error {{no member named 'bad1' in 'struct test'}}
var . bad2 ; // expected-error {{no member named 'bad2' in 'struct test'}}
}
2011-02-22 20:32:04 +00:00
// Enumeration types with a fixed underlying type.
const int seventeen = 17 ;
typedef int Int ;
struct X0 {
enum E1 : Int { SomeOtherValue } field ; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
enum E1 : seventeen ;
} ;
2011-02-22 21:42:31 +00:00
enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
2011-02-22 20:32:04 +00:00
SomeValue = 0x100000000
} ;
2011-05-11 22:28:19 +00:00
void pointer_to_integral_type_conv ( char * ptr ) {
2020-03-04 13:18:59 -08:00
char ch = ( char ) ptr ;
short sh = ( short ) ptr ;
ch = ( char ) ptr ;
sh = ( short ) ptr ;
2013-06-06 09:16:36 +00:00
2020-03-04 13:18:59 -08:00
// This is valid ISO C.
_Bool b = ( _Bool ) ptr ;
2012-02-01 00:41:00 +00:00
}
typedef struct {
UNKNOWN u ; // expected-error {{unknown type name 'UNKNOWN'}}
} AA ;
typedef struct {
AA ; // expected-warning {{anonymous structs are a Microsoft extension}}
} BB ;
2012-02-23 01:19:31 +00:00
2014-09-18 00:42:05 +00:00
struct anon_fault {
struct undefined ; // expected-warning {{anonymous structs are a Microsoft extension}}
// expected-error@-1 {{field has incomplete type 'struct undefined'}}
// expected-note@-2 {{forward declaration of 'struct undefined'}}
} ;
const int anon_falt_size = sizeof ( struct anon_fault ) ;
2013-12-18 23:30:06 +00:00
__declspec ( deprecated ( " This is deprecated " ) ) enum DE1 { one , two } e1 ; // expected-note {{'e1' has been explicitly marked deprecated here}}
struct __declspec ( deprecated ) DS1 { int i ; float f ; } ; // expected-note {{'DS1' has been explicitly marked deprecated here}}
2012-02-23 01:19:31 +00:00
# define MY_TEXT "This is also deprecated"
2013-12-18 23:30:06 +00:00
__declspec ( deprecated ( MY_TEXT ) ) void Dfunc1 ( void ) { } // expected-note {{'Dfunc1' has been explicitly marked deprecated here}}
2012-02-23 01:19:31 +00:00
2021-07-10 15:52:54 +02:00
struct __declspec ( deprecated ( 123 ) ) DS2 { } ; // expected-error {{expected string literal as argument of 'deprecated' attribute}}
2012-06-19 22:09:27 +00:00
2012-02-23 01:19:31 +00:00
void test ( void ) {
e1 = one ; // expected-warning {{'e1' is deprecated: This is deprecated}}
struct DS1 s = { 0 } ; // expected-warning {{'DS1' is deprecated}}
Dfunc1 ( ) ; // expected-warning {{'Dfunc1' is deprecated: This is also deprecated}}
enum DE1 no ; // no warning because E1 is not deprecated
}
2013-05-22 23:25:32 +00:00
int __sptr wrong1 ; // expected-error {{'__sptr' attribute only applies to pointer arguments}}
// The modifier must follow the asterisk
int __sptr * wrong_psp ; // expected-error {{'__sptr' attribute only applies to pointer arguments}}
int * __sptr __uptr wrong2 ; // expected-error {{'__sptr' and '__uptr' attributes are not compatible}}
int * __sptr __sptr wrong3 ; // expected-warning {{attribute '__sptr' is already applied}}
// It is illegal to overload based on the type attribute.
void ptr_func ( int * __ptr32 i ) { } // expected-note {{previous definition is here}}
void ptr_func ( int * __ptr64 i ) { } // expected-error {{redefinition of 'ptr_func'}}
// It is also illegal to overload based on the pointer type attribute.
void ptr_func2 ( int * __sptr __ptr32 i ) { } // expected-note {{previous definition is here}}
void ptr_func2 ( int * __uptr __ptr32 i ) { } // expected-error {{redefinition of 'ptr_func2'}}
Add support for the MS qualifiers __ptr32, __ptr64, __sptr, __uptr.
Summary:
This adds parsing of the qualifiers __ptr32, __ptr64, __sptr, and __uptr and
lowers them to the corresponding address space pointer for 32-bit and 64-bit pointers.
(32/64-bit pointers added in https://reviews.llvm.org/D69639)
A large part of this patch is making these pointers ignore the address space
when doing things like overloading and casting.
https://bugs.llvm.org/show_bug.cgi?id=42359
Reviewers: rnk, rsmith
Subscribers: jholewinski, jvesely, nhaehnle, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71039
2019-10-24 16:34:25 -07:00
// Check for warning when return types have the type attribute.
2022-02-03 16:39:21 -05:00
void * __ptr32 ptr_func3 ( void ) { return 0 ; } // expected-note {{previous definition is here}}
void * __ptr64 ptr_func3 ( void ) { return 0 ; } // expected-error {{redefinition of 'ptr_func3'}}
Add support for the MS qualifiers __ptr32, __ptr64, __sptr, __uptr.
Summary:
This adds parsing of the qualifiers __ptr32, __ptr64, __sptr, and __uptr and
lowers them to the corresponding address space pointer for 32-bit and 64-bit pointers.
(32/64-bit pointers added in https://reviews.llvm.org/D69639)
A large part of this patch is making these pointers ignore the address space
when doing things like overloading and casting.
https://bugs.llvm.org/show_bug.cgi?id=42359
Reviewers: rnk, rsmith
Subscribers: jholewinski, jvesely, nhaehnle, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71039
2019-10-24 16:34:25 -07:00
// Test that __ptr32/__ptr64 can be passed as arguments with other address
// spaces.
void ptr_func4 ( int * i ) ;
void ptr_func5 ( int * __ptr32 i ) ;
2022-02-03 16:39:21 -05:00
void test_ptr_arguments ( void ) {
Add support for the MS qualifiers __ptr32, __ptr64, __sptr, __uptr.
Summary:
This adds parsing of the qualifiers __ptr32, __ptr64, __sptr, and __uptr and
lowers them to the corresponding address space pointer for 32-bit and 64-bit pointers.
(32/64-bit pointers added in https://reviews.llvm.org/D69639)
A large part of this patch is making these pointers ignore the address space
when doing things like overloading and casting.
https://bugs.llvm.org/show_bug.cgi?id=42359
Reviewers: rnk, rsmith
Subscribers: jholewinski, jvesely, nhaehnle, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71039
2019-10-24 16:34:25 -07:00
int * __ptr64 i64 ;
ptr_func4 ( i64 ) ;
ptr_func5 ( i64 ) ;
}
2013-05-22 23:25:32 +00:00
int * __sptr __ptr32 __sptr wrong4 ; // expected-warning {{attribute '__sptr' is already applied}}
__ptr32 int * wrong5 ; // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
int * wrong6 __ptr32 ; // expected-error {{expected ';' after top level declarator}} expected-warning {{declaration does not declare anything}}
int * __ptr32 __ptr64 wrong7 ; // expected-error {{'__ptr32' and '__ptr64' attributes are not compatible}}
int * __ptr32 __ptr32 wrong8 ; // expected-warning {{attribute '__ptr32' is already applied}}
int * ( __ptr32 __sptr wrong9 ) ; // expected-error {{'__sptr' attribute only applies to pointer arguments}} // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
2022-08-09 11:06:51 -04:00
int * ( __ptr32 wrong10 ) ; // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
int * ( __ptr64 wrong11 ) ; // expected-error {{'__ptr64' attribute only applies to pointer arguments}}
int * ( __ptr32 __ptr64 wrong12 ) ; // expected-error {{'__ptr32' attribute only applies to pointer arguments}} // expected-error {{'__ptr64' attribute only applies to pointer arguments}}
2013-05-22 23:25:32 +00:00
typedef int * T ;
2022-08-09 11:06:51 -04:00
T __ptr32 ok1 ;
T __ptr64 ok2 ;
T __ptr32 __ptr64 wrong13 ; // expected-error {{'__ptr32' and '__ptr64' attributes are not compatible}}
typedef int * __ptr32 T1 ;
T1 ok3 ;
T1 __ptr32 wrong14 ; // expected-warning {{attribute '__ptr32' is already applied}}
T1 __ptr64 wrong15 ; // expected-error {{'__ptr32' and '__ptr64' attributes are not compatible}}
typedef int * __ptr64 T2 ;
T2 ok4 ;
T2 __ptr64 wrong16 ; // expected-warning {{attribute '__ptr64' is already applied}}
T2 __ptr32 wrong17 ; // expected-error {{'__ptr32' and '__ptr64' attributes are not compatible}}
typedef int * __ptr32 __ptr64 wrong18 ; // expected-error {{'__ptr32' and '__ptr64' attributes are not compatible}}
2014-03-26 15:38:33 +00:00
typedef char * my_va_list ;
2014-03-26 22:52:23 +00:00
void __va_start ( my_va_list * ap , . . . ) ; // expected-note {{passing argument to parameter 'ap' here}}
2014-03-26 15:38:33 +00:00
void vmyprintf ( const char * f , my_va_list ap ) ;
void myprintf ( const char * f , . . . ) {
my_va_list ap ;
if ( 1 ) {
__va_start ( & ap , f ) ;
vmyprintf ( f , ap ) ;
ap = 0 ;
} else {
__va_start ( ap , f ) ; // expected-warning {{incompatible pointer types passing 'my_va_list'}}
}
}
2016-05-11 18:38:21 +00:00
// __unaligned handling
2022-02-03 16:39:21 -05:00
void test_unaligned ( void ) {
2016-05-11 18:38:21 +00:00
__unaligned int * p1 = 0 ;
int * p2 = p1 ; // expected-warning {{initializing 'int *' with an expression of type '__unaligned int *' discards qualifiers}}
__unaligned int * p3 = p2 ;
}
2016-05-26 10:06:01 +00:00
void test_unaligned2 ( int x [ __unaligned 4 ] ) { }