blob: ad3406e304a783d800b205dac91e2e157c354e90 [file] [log] [blame]
David Blaikieaeef2ae2012-03-15 05:09:31 +00001// RUN: %clang_cc1 %s -verify -fsyntax-only -Wvector-conversion
Anders Carlssone1af1d22007-11-30 04:21:22 +00002typedef unsigned int v2u __attribute__ ((vector_size (8)));
3typedef signed int v2s __attribute__ ((vector_size (8)));
4typedef signed int v1s __attribute__ ((vector_size (4)));
5typedef float v2f __attribute__ ((vector_size(8)));
6typedef signed short v4ss __attribute__ ((vector_size (8)));
7
Chris Lattnerec3a1562009-10-17 20:33:28 +00008void test1() {
Anders Carlssone1af1d22007-11-30 04:21:22 +00009 v2s v1;
10 v2u v2;
11 v1s v3;
12 v2f v4;
13 v4ss v5;
14
Benjamin Kramer1adc8c32014-04-25 20:41:38 +000015 v1 = v2; // expected-warning {{incompatible vector types assigning to 'v2s' (vector of 2 'int' values) from 'v2u' (vector of 2 'unsigned int' values)}}
16 v1 = v3; // expected-error {{assigning to 'v2s' (vector of 2 'int' values) from incompatible type 'v1s' (vector of 1 'int' value)}}
17 v1 = v4; // expected-warning {{incompatible vector types assigning to 'v2s' (vector of 2 'int' values) from 'v2f' (vector of 2 'float' values)}}
18 v1 = v5; // expected-warning {{incompatible vector types assigning to 'v2s' (vector of 2 'int' values) from 'v4ss' (vector of 4 'short' values)}}
Anders Carlssone1af1d22007-11-30 04:21:22 +000019
Benjamin Kramer1adc8c32014-04-25 20:41:38 +000020 v2 = v1; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from 'v2s' (vector of 2 'int' values)}}
21 v2 = v3; // expected-error {{assigning to 'v2u' (vector of 2 'unsigned int' values) from incompatible type 'v1s' (vector of 1 'int' value)}}
22 v2 = v4; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from 'v2f' (vector of 2 'float' values)}}
23 v2 = v5; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from 'v4ss' (vector of 4 'short' values)}}
Anders Carlssone1af1d22007-11-30 04:21:22 +000024
Benjamin Kramer1adc8c32014-04-25 20:41:38 +000025 v3 = v1; // expected-error {{assigning to 'v1s' (vector of 1 'int' value) from incompatible type 'v2s' (vector of 2 'int' values)}}
26 v3 = v2; // expected-error {{assigning to 'v1s' (vector of 1 'int' value) from incompatible type 'v2u' (vector of 2 'unsigned int' values)}}
27 v3 = v4; // expected-error {{assigning to 'v1s' (vector of 1 'int' value) from incompatible type 'v2f' (vector of 2 'float' values)}}
28 v3 = v5; // expected-error {{assigning to 'v1s' (vector of 1 'int' value) from incompatible type 'v4ss'}}
Anders Carlssone1af1d22007-11-30 04:21:22 +000029
Benjamin Kramer1adc8c32014-04-25 20:41:38 +000030 v4 = v1; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from 'v2s' (vector of 2 'int' values)}}
31 v4 = v2; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from 'v2u' (vector of 2 'unsigned int' values)}}
32 v4 = v3; // expected-error {{assigning to 'v2f' (vector of 2 'float' values) from incompatible type 'v1s' (vector of 1 'int' value)}}
33 v4 = v5; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from 'v4ss' (vector of 4 'short' values)}}
Anders Carlssone1af1d22007-11-30 04:21:22 +000034
Benjamin Kramer1adc8c32014-04-25 20:41:38 +000035 v5 = v1; // expected-warning {{incompatible vector types assigning to 'v4ss' (vector of 4 'short' values) from 'v2s' (vector of 2 'int' values)}}
36 v5 = v2; // expected-warning {{incompatible vector types assigning to 'v4ss' (vector of 4 'short' values) from 'v2u' (vector of 2 'unsigned int' values)}}
37 v5 = v3; // expected-error {{assigning to 'v4ss' (vector of 4 'short' values) from incompatible type 'v1s' (vector of 1 'int' value)}}
38 v5 = v4; // expected-warning {{incompatible vector types assigning to 'v4ss' (vector of 4 'short' values) from 'v2f'}}
Anders Carlssone1af1d22007-11-30 04:21:22 +000039}
Chris Lattnerc9c296d2008-05-12 18:31:17 +000040
41// PR2263
Chris Lattnerec3a1562009-10-17 20:33:28 +000042float test2(__attribute__((vector_size(16))) float a, int b) {
Chris Lattnerc9c296d2008-05-12 18:31:17 +000043 return a[b];
44}
45
Chris Lattnerec3a1562009-10-17 20:33:28 +000046// PR4838
47typedef long long __attribute__((__vector_size__(2 * sizeof(long long))))
48longlongvec;
49
Douglas Gregor4f4946a2010-04-22 00:20:18 +000050void test3a(longlongvec *); // expected-note{{passing argument to parameter here}}
Chris Lattnerec3a1562009-10-17 20:33:28 +000051void test3(const unsigned *src) {
Chris Lattner53fa0492010-09-05 00:04:01 +000052 test3a(src); // expected-warning {{incompatible pointer types passing 'const unsigned int *' to parameter of type 'longlongvec *'}}
Chris Lattnerec3a1562009-10-17 20:33:28 +000053}