2012-03-15 13:09:31 +08:00
// RUN: %clang_cc1 -fsyntax-only %s -verify -Wvector-conversion
2007-11-27 13:51:55 +08:00
typedef long long t1 __attribute__ ( ( vector_size ( 8 ) ) ) ;
typedef char t2 __attribute__ ( ( vector_size ( 16 ) ) ) ;
typedef float t3 __attribute__ ( ( vector_size ( 16 ) ) ) ;
2015-07-24 07:54:07 +08:00
typedef short s2 __attribute__ ( ( vector_size ( 4 ) ) ) ;
typedef enum { Evalue = 0x10000 } E ;
2007-11-27 13:51:55 +08:00
void f ( )
{
t1 v1 ;
t2 v2 ;
t3 v3 ;
2015-07-24 07:54:07 +08:00
s2 v4 ;
E e ;
e = ( E ) v4 ;
v4 = ( s2 ) e ;
2007-11-27 13:51:55 +08:00
2012-10-19 20:36:49 +08:00
v2 = ( t2 ) v1 ; / / expected - error { { invalid conversion between vector type \
2014-04-26 04:41:38 +08:00
' t2 ' ( vector of 16 ' char ' values ) and ' t1 ' ( vector of 1 ' long long ' value ) of different size } }
2012-10-19 20:36:49 +08:00
v1 = ( t1 ) v2 ; / / expected - error { { invalid conversion between vector type \
2014-04-26 04:41:38 +08:00
' t1 ' ( vector of 1 ' long long ' value ) and ' t2 ' ( vector of 16 ' char ' values ) of different size } }
2007-11-27 13:51:55 +08:00
v3 = ( t3 ) v2 ;
2012-10-19 20:36:49 +08:00
v1 = ( t1 ) ( char * ) 10 ; / / expected - error { { invalid conversion between vector \
2014-04-26 04:41:38 +08:00
type ' t1 ' ( vector of 1 ' long long ' value ) and scalar type ' char * ' } }
2007-11-27 13:51:55 +08:00
v1 = ( t1 ) ( long long ) 10 ;
2012-10-19 20:36:49 +08:00
v1 = ( t1 ) ( short ) 10 ; / / expected - error { { invalid conversion between vector \
2014-04-26 04:41:38 +08:00
type ' t1 ' ( vector of 1 ' long long ' value ) and integer type ' short ' of different size } }
2007-11-27 13:51:55 +08:00
long long r1 = ( long long ) v1 ;
2012-10-19 20:36:49 +08:00
short r2 = ( short ) v1 ; / / expected - error { { invalid conversion between vector \
2014-04-26 04:41:38 +08:00
type ' t1 ' ( vector of 1 ' long long ' value ) and integer type ' short ' of different size } }
2012-10-19 20:36:49 +08:00
char * r3 = ( char * ) v1 ; / / expected - error { { invalid conversion between vector \
2014-04-26 04:41:38 +08:00
type ' t1 ' ( vector of 1 ' long long ' value ) and scalar type ' char * ' } }
2007-11-27 13:51:55 +08:00
}
2009-04-18 02:39:25 +08:00
2010-04-22 08:20:18 +08:00
void f2 ( t2 X ) ; // expected-note{{passing argument to parameter 'X' here}}
2009-04-18 02:39:25 +08:00
void f3 ( t3 Y ) {
2014-04-26 04:41:38 +08:00
f2 ( Y ) ; // expected-warning {{incompatible vector types passing 't3' (vector of 4 'float' values) to parameter of type 't2' (vector of 16 'char' values)}}
2009-04-18 02:39:25 +08:00
}
2014-01-09 15:58:22 +08:00
typedef float float2 __attribute__ ( ( vector_size ( 8 ) ) ) ;
void f4 ( ) {
float2 f2 ;
double d ;
f2 + = d ;
d + = f2 ;
}
2014-02-05 07:58:19 +08:00
// rdar://15931426
// Don't permit a lax conversion to and from a pointer type.
typedef short short_sizeof_pointer __attribute__ ( ( vector_size ( sizeof ( void * ) ) ) ) ;
void f5 ( ) {
short_sizeof_pointer v ;
void * ptr ;
2014-04-26 04:49:10 +08:00
v = ptr ; // expected-error-re {{assigning to 'short_sizeof_pointer' (vector of {{[0-9]+}} 'short' values) from incompatible type 'void *'}}
2014-02-05 07:58:19 +08:00
ptr = v ; // expected-error {{assigning to 'void *' from incompatible type 'short_sizeof_pointer'}}
}