xref: /llvm-project/clang/test/Sema/altivec-init.c (revision 2fe49ea0d07d503aedd0872bf0a66724552d4dcf)
1 // RUN: %clang_cc1 %s -triple=powerpc-ibm-aix -target-feature +altivec -verify -pedantic -fsyntax-only
2 
3 typedef int v4 __attribute((vector_size(16)));
4 typedef short v8 __attribute((vector_size(16)));
5 
foo(void)6 v8 foo(void) {
7   v8 a;
8   v4 b;
9   a = (v8){4, 2};
10   b = (v4)(5, 6, 7, 8, 9); // expected-warning {{excess elements in vector initializer}}
11   b = (v4)(5, 6, 8, 8.0f);
12 
13   vector int vi;
14   vi = (vector int)(1);
15   vi = (vector int)(1, 2);          // expected-error {{number of elements must be either one or match the size of the vector}}
16   vi = (vector int)(1, 2, 3, 4);
17   vi = (vector int)(1, 2, 3, 4, 5); // expected-warning {{excess elements in vector initializer}}
18   vi = (vector int){1};
19   vi = (vector int){1, 2};
20   vi = (vector int){1, 2, 3, 4, 5}; // expected-warning {{excess elements in vector initializer}}
21   vector float vf;
22   vf = (vector float)(1.0);
23 
24   return (v8){0, 1, 2, 3, 1, 2, 3, 4};
25 
26   // FIXME: test that (type)(fn)(args) still works with -maltivec
27   // FIXME: test that c++ overloaded commas still work -maltivec
28 }
29 
f(v4 a)30 void __attribute__((__overloadable__)) f(v4 a)
31 {
32 }
33 
f(int a)34 void __attribute__((__overloadable__)) f(int a)
35 {
36 }
37 
test(void)38 void test(void)
39 {
40   v4 vGCC;
41   vector int vAltiVec;
42 
43   f(vAltiVec);
44   vGCC = vAltiVec;
45   int res = vGCC > vAltiVec;
46   vAltiVec = 0 ? vGCC : vGCC;
47 }
48 
49 typedef struct VecMem {
50   vector signed vec;
51 } VecMem;
52 
53 // The following should not assert.  See qiongsiwu1's comment here:
54 // https://reviews.llvm.org/D115670
test2(void)55 void test2(void) {
56   vector signed local_vec = {1, 2, 3, 4};
57   VecMem VM;
58   VM.vec = ++local_vec;
59 }
60 
61