1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
typedef unsigned char uchar;
typedef unsigned char uchar2 __attribute__((ext_vector_type(2)));
typedef char char2 __attribute__((ext_vector_type(2)));
typedef char char3 __attribute__((ext_vector_type(3)));
typedef int int2 __attribute__((ext_vector_type(2)));
typedef float float2 __attribute__((ext_vector_type(2)));
// ** Positive tests **
// all scalars, but widths do not match.
int ptest01(char C, char X, int Y)
{
return C ? X : Y;
}
char ptest02(int C, char X, char Y)
{
return C ? X : Y;
}
// scalar condition and mixed-width vectors and scalars
int2 ptest03(char C, char X, int2 Y)
{
return C ? X : Y;
}
// uniform vectors
char2 ptest04(char2 X, char2 Y, char2 C)
{
return C ? X : Y;
}
// vector condition and mixed scalar operands
int2 ptest05(int2 C, int X, char Y)
{
return C ? X : Y;
}
// vector condition and matching scalar operands
float2 ptest06(int2 C, float X, float Y)
{
return C ? X : Y;
}
// vector condition and mixed scalar operands
float2 ptest07(int2 C, int X, float Y)
{
return C ? X : Y;
}
// vector condition and mixed scalar and vector operands
float2 ptest08(int2 C, int X, float2 Y)
{
return C ? X : Y;
}
// Actual comparison expression
float2 ptest09(float2 A, float2 B, float2 C, float2 D)
{
return A < B ? C : D;
}
// ** Negative tests **
int2 ntest01(char2 C, int X, int Y)
{
return C ? X : Y; // expected-error {{vector condition type 'char2' (vector of 2 'char' values) and result type (vector of 2 'int' values) do not have elements of the same size}}
}
int2 ntest02(char2 C, int2 X, int2 Y)
{
return C ? X : Y; // expected-error {{vector condition type 'char2' (vector of 2 'char' values) and result type 'int2' (vector of 2 'int' values) do not have elements of the same size}}
}
uchar2 ntest03(int2 C, uchar X, uchar Y)
{
return C ? X : Y; // expected-error {{vector condition type 'int2' (vector of 2 'int' values) and result type (vector of 2 'unsigned char' values) do not have elements of the same size}}
}
float2 ntest04(int2 C, int2 X, float2 Y)
{
return C ? X : Y; // expected-error {{implicit conversions between vector types ('int2' (vector of 2 'int' values) and 'float2' (vector of 2 'float' values)) are not permitted}}
}
float2 ntest05(int2 C, int2 X, float Y)
{
return C ? X : Y; // expected-error {{scalar operand type has greater rank than the type of the vector element. ('int2' (vector of 2 'int' values) and 'float'}}
}
char2 ntest06(int2 C, char2 X, char2 Y)
{
return C ? X : Y; // expected-error {{vector condition type 'int2' (vector of 2 'int' values) and result type 'char2' (vector of 2 'char' values) do not have elements of the same size}}
}
float ntest07(float C, float X, float Y)
{
return C ? X : Y; // expected-error {{used type 'float' where floating point type is not allowed}}
}
float2 ntest08(float2 C, float2 X, float2 Y)
{
return C ? X : Y; // expected-error {{used type 'float2' (vector of 2 'float' values) where floating point type is not allowed}}
}
// Trying to create a int2 vector out of pointers.
int2 ntest09(int2 C, global int *X, global int *Y)
{
return C ? X : Y; // expected-error {{used type '__global int *' where integer or floating point type is required}}
}
char3 ntest10(char C, char3 X, char2 Y)
{
return C ? X : Y; // expected-error {{implicit conversions between vector types ('char3' (vector of 3 'char' values) and 'char2' (vector of 2 'char' values)) are not permitted}}
}
char3 ntest11(char2 C, char3 X, char Y)
{
return C ? X : Y; // expected-error {{vector condition type 'char2' (vector of 2 'char' values) and result type 'char3' (vector of 3 'char' values) do not have the same number of elements}}
}
int foo1(int);
int foo2(int);
unsigned int ntest12(int2 C)
{
return (unsigned int)(C ? foo1 : foo2); // expected-error {{taking address of function is not allowed}} expected-error {{taking address of function is not allowed}}
}
|