xref: /llvm-project/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-error.c (revision a4558a4a53eda8d170bbd2c358d383bb0a13f91f)
1 // REQUIRES: powerpc-registered-target
2 // RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu -fsyntax-only \
3 // RUN:   -Wall -Werror -verify %s
4 // RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu -fsyntax-only \
5 // RUN:   -Wall -Werror -verify %s
6 // RUN: %clang_cc1 -triple powerpc64-unknown-aix -fsyntax-only \
7 // RUN:   -Wall -Werror -verify %s
8 // RUN: %clang_cc1 -triple powerpc-unknown-aix -fsyntax-only \
9 // RUN:   -Wall -Werror -verify %s
10 
11 extern long long lla, llb;
12 extern int ia, ib;
13 extern unsigned int ui;
14 extern unsigned long long ull;
15 extern const int cia;
16 extern unsigned long ula;
17 
test_trap(void)18 void test_trap(void) {
19 #ifdef __PPC64__
20   __tdw(lla, llb, 50); //expected-error {{argument value 50 is outside the valid range [1, 31]}}
21   __tdw(lla, llb, 0); //expected-error {{argument value 0 is outside the valid range [1, 31]}}
22 #endif
23   __tw(ia, ib, 50); //expected-error {{argument value 50 is outside the valid range [1, 31]}}
24   __tw(ia, ib, 0); //expected-error {{argument value 0 is outside the valid range [1, 31]}}
25 }
26 
test_builtin_ppc_rldimi()27 void test_builtin_ppc_rldimi() {
28   unsigned int shift;
29   unsigned long long mask;
30   unsigned long long res = __builtin_ppc_rldimi(ull, ull, shift, 7); // expected-error {{argument to '__builtin_ppc_rldimi' must be a constant integer}}
31   res = __builtin_ppc_rldimi(ull, ull, 63, mask);                    // expected-error {{argument to '__builtin_ppc_rldimi' must be a constant integer}}
32   res = __builtin_ppc_rldimi(ull, ull, 63, 0xFFFF000000000F00);      // expected-error {{argument 3 value should represent a contiguous bit field}}
33   res = __builtin_ppc_rldimi(ull, ull, 64, 0xFFFF000000000000);      // expected-error {{argument value 64 is outside the valid range [0, 63]}}
34 }
35 
test_builtin_ppc_rlwimi()36 void test_builtin_ppc_rlwimi() {
37   unsigned int shift;
38   unsigned int mask;
39   unsigned int res = __builtin_ppc_rlwimi(ui, ui, shift, 7); // expected-error {{argument to '__builtin_ppc_rlwimi' must be a constant integer}}
40   res = __builtin_ppc_rlwimi(ui, ui, 31, mask);              // expected-error {{argument to '__builtin_ppc_rlwimi' must be a constant integer}}
41   res = __builtin_ppc_rlwimi(ui, ui, 31, 0xFFFF0F00);        // expected-error {{argument 3 value should represent a contiguous bit field}}
42 }
43 
test_builtin_ppc_rlwnm()44 void test_builtin_ppc_rlwnm() {
45   unsigned int mask;
46   unsigned int res = __builtin_ppc_rlwnm(ui, 31, mask);              // expected-error {{argument to '__builtin_ppc_rlwnm' must be a constant integer}}
47   res = __builtin_ppc_rlwnm(ui, 31, 0xFF0F0F00);        // expected-error {{argument 2 value should represent a contiguous bit field}}
48 }
49 
50 extern unsigned int usi;
51 extern double d;
52 extern float f;
53 
testMathBuiltin(void)54 void testMathBuiltin(void) {
55   __mtfsb0(usi); //expected-error {{argument to '__builtin_ppc_mtfsb0' must be a constant integer}}
56   __mtfsb0(32); //expected-error {{argument value 32 is outside the valid range [0, 31]}}
57   __mtfsb1(usi); //expected-error {{argument to '__builtin_ppc_mtfsb1' must be a constant integer}}
58   __mtfsb1(45); //expected-error {{argument value 45 is outside the valid range [0, 31]}}
59   __mtfsf(usi, usi); //expected-error {{argument to '__builtin_ppc_mtfsf' must be a constant integer}}
60   __mtfsf(350, usi); //expected-error {{argument value 350 is outside the valid range [0, 255]}}
61   __mtfsfi(usi, 0); //expected-error {{argument to '__builtin_ppc_mtfsfi' must be a constant integer}}
62   __mtfsfi(0, usi); //expected-error {{argument to '__builtin_ppc_mtfsfi' must be a constant integer}}
63   __mtfsfi(8, 0); //expected-error {{argument value 8 is outside the valid range [0, 7]}}
64   __mtfsfi(5, 24); //expected-error {{argument value 24 is outside the valid range [0, 15]}}
65 }
66 
testrdlam(unsigned long long rs,unsigned int shift,unsigned int not_const)67 unsigned long long testrdlam(unsigned long long rs, unsigned int shift, unsigned int not_const) {
68   // The third parameter is a mask that must be a constant that represents a
69   // contiguous bit field.
70   unsigned long long Return;
71   // Third parameter is not a constant.
72   Return = __rdlam(rs, shift, not_const); //expected-error {{argument to '__builtin_ppc_rdlam' must be a constant integer}}
73   // Third parameter is a constant but not a contiguous bit field.
74   return __rdlam(rs, shift, 0xF4) + Return; //expected-error {{argument 2 value should represent a contiguous bit field}}
75 }
76 
testalignx(const void * pointer,unsigned int alignment)77 void testalignx(const void *pointer, unsigned int alignment) {
78   // The alignment must be an immediate.
79   __alignx(alignment, pointer); //expected-error {{argument to '__builtin_ppc_alignx' must be a constant integer}}
80   // The alignment must be a power of 2.
81   __alignx(0x0, pointer); //expected-error {{argument should be a power of 2}}
82   // The alignment must be a power of 2.
83   __alignx(0xFF, pointer); //expected-error {{argument should be a power of 2}}
84 }
85 
86 #ifndef __PPC64__
testbpermd(long long bit_selector,long long source)87 long long testbpermd(long long bit_selector, long long source) {
88   return __bpermd(bit_selector, source); //expected-error {{this builtin is only available on 64-bit targets}}
89 }
90 
testdivde(long long dividend,long long divisor)91 long long testdivde(long long dividend, long long divisor) {
92   return __divde(dividend, divisor); //expected-error {{this builtin is only available on 64-bit targets}}
93 }
94 
testdivdeu(unsigned long long dividend,unsigned long long divisor)95 unsigned long long testdivdeu(unsigned long long dividend, unsigned long long divisor) {
96   return __divdeu(dividend, divisor); //expected-error {{this builtin is only available on 64-bit targets}}
97 }
98 
test_darn()99 int test_darn() {
100   return __darn(); //expected-error {{this builtin is only available on 64-bit targets}}
101 }
102 
test_darn_raw()103 int test_darn_raw() {
104   return __darn_raw(); //expected-error {{this builtin is only available on 64-bit targets}}
105 }
106 
test_builtin_ppc_compare_and_swaplp(long a,long b,long c)107 int test_builtin_ppc_compare_and_swaplp(long a, long b, long c) {
108   return __compare_and_swaplp(&a, &b, c); // expected-error {{this builtin is only available on 64-bit targets}}
109 }
110 
test_builtin_ppc_fetch_and_addlp(long a,long b)111 void test_builtin_ppc_fetch_and_addlp(long a, long b) {
112   __fetch_and_addlp(&a, b); // expected-error {{this builtin is only available on 64-bit targets}}
113 }
114 
test_builtin_ppc_fetch_and_andlp(unsigned long a,unsigned long b)115 void test_builtin_ppc_fetch_and_andlp(unsigned long a, unsigned long b) {
116   __fetch_and_andlp(&a, b); // expected-error {{this builtin is only available on 64-bit targets}}
117 }
test_builtin_ppc_fetch_and_orlp(unsigned long a,unsigned long b)118 void test_builtin_ppc_fetch_and_orlp(unsigned long a, unsigned long b) {
119   __fetch_and_orlp(&a, b); // expected-error {{this builtin is only available on 64-bit targets}}
120 }
121 
test_builtin_ppc_fetch_and_swaplp(unsigned long a,unsigned long b)122 void test_builtin_ppc_fetch_and_swaplp(unsigned long a, unsigned long b) {
123   __fetch_and_swaplp(&a, b); // expected-error {{this builtin is only available on 64-bit targets}}
124 }
125 #endif
126 
test_mfspr(void)127 unsigned long test_mfspr(void) {
128   return __mfspr(cia); //expected-error {{argument to '__builtin_ppc_mfspr' must be a constant integer}}
129 }
130 
test_mtspr(void)131 void test_mtspr(void) {
132    __mtspr(cia, ula); //expected-error {{argument to '__builtin_ppc_mtspr' must be a constant integer}}
133 }
134