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