xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/complex.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -emit-llvm-only %s
2f4a2713aSLionel Sambuc 
main(void)3f4a2713aSLionel Sambuc int main(void)
4f4a2713aSLionel Sambuc {
5f4a2713aSLionel Sambuc   double _Complex a = 5;
6f4a2713aSLionel Sambuc   double _Complex b = 42;
7f4a2713aSLionel Sambuc 
8f4a2713aSLionel Sambuc   return a * b != b * a;
9f4a2713aSLionel Sambuc }
10f4a2713aSLionel Sambuc 
11f4a2713aSLionel Sambuc _Complex double bar(int);
12f4a2713aSLionel Sambuc void test(_Complex double*);
13f4a2713aSLionel Sambuc void takecomplex(_Complex double);
14f4a2713aSLionel Sambuc 
test2(int c)15f4a2713aSLionel Sambuc void test2(int c) {
16f4a2713aSLionel Sambuc   _Complex double X;
17f4a2713aSLionel Sambuc   X = bar(1);
18f4a2713aSLionel Sambuc   test(&X);
19f4a2713aSLionel Sambuc   takecomplex(X);
20f4a2713aSLionel Sambuc }
21f4a2713aSLionel Sambuc 
22f4a2713aSLionel Sambuc _Complex double g1, g2;
23f4a2713aSLionel Sambuc _Complex float cf;
24f4a2713aSLionel Sambuc double D;
25f4a2713aSLionel Sambuc 
test3()26f4a2713aSLionel Sambuc void test3() {
27f4a2713aSLionel Sambuc   g1 = g1 + g2;
28f4a2713aSLionel Sambuc   g1 = g1 - g2;
29f4a2713aSLionel Sambuc   g1 = g1 * g2;
30f4a2713aSLionel Sambuc   g1 = +-~g1;
31f4a2713aSLionel Sambuc 
32f4a2713aSLionel Sambuc   double Gr = __real g1;
33f4a2713aSLionel Sambuc 
34f4a2713aSLionel Sambuc   cf += D;
35f4a2713aSLionel Sambuc   D += cf;
36f4a2713aSLionel Sambuc   cf /= g1;
37f4a2713aSLionel Sambuc   g1 = g1 + D;
38f4a2713aSLionel Sambuc   g1 = D + g1;
39f4a2713aSLionel Sambuc }
40f4a2713aSLionel Sambuc 
41f4a2713aSLionel Sambuc __complex__ int ci1, ci2;
42f4a2713aSLionel Sambuc __complex__ short cs;
43f4a2713aSLionel Sambuc int i;
test3int()44f4a2713aSLionel Sambuc void test3int() {
45f4a2713aSLionel Sambuc   ci1 = ci1 + ci2;
46f4a2713aSLionel Sambuc   ci1 = ci1 - ci2;
47f4a2713aSLionel Sambuc   ci1 = ci1 * ci2;
48f4a2713aSLionel Sambuc   ci1 = +-~ci1;
49f4a2713aSLionel Sambuc 
50f4a2713aSLionel Sambuc   i = __real ci1;
51f4a2713aSLionel Sambuc 
52f4a2713aSLionel Sambuc   cs += i;
53f4a2713aSLionel Sambuc   D += cf;
54f4a2713aSLionel Sambuc   cs /= ci1;
55f4a2713aSLionel Sambuc   ci1 = ci1 + i;
56f4a2713aSLionel Sambuc   ci1 = i + ci1;
57f4a2713aSLionel Sambuc }
58f4a2713aSLionel Sambuc 
t1()59f4a2713aSLionel Sambuc void t1() {
60f4a2713aSLionel Sambuc   (__real__ cf) = 4.0;
61f4a2713aSLionel Sambuc }
62f4a2713aSLionel Sambuc 
t2()63f4a2713aSLionel Sambuc void t2() {
64f4a2713aSLionel Sambuc   (__imag__ cf) = 4.0;
65f4a2713aSLionel Sambuc }
66f4a2713aSLionel Sambuc 
67f4a2713aSLionel Sambuc // PR1960
t3()68f4a2713aSLionel Sambuc void t3() {
69f4a2713aSLionel Sambuc   __complex__ long long v = 2;
70f4a2713aSLionel Sambuc }
71f4a2713aSLionel Sambuc 
72f4a2713aSLionel Sambuc // PR3131
73f4a2713aSLionel Sambuc float _Complex t4();
74f4a2713aSLionel Sambuc 
t5()75f4a2713aSLionel Sambuc void t5() {
76f4a2713aSLionel Sambuc   float _Complex x = t4();
77f4a2713aSLionel Sambuc }
78f4a2713aSLionel Sambuc 
t6()79f4a2713aSLionel Sambuc void t6() {
80f4a2713aSLionel Sambuc   g1++;
81f4a2713aSLionel Sambuc   g1--;
82f4a2713aSLionel Sambuc   ++g1;
83f4a2713aSLionel Sambuc   --g1;
84f4a2713aSLionel Sambuc   ci1++;
85f4a2713aSLionel Sambuc   ci1--;
86f4a2713aSLionel Sambuc   ++ci1;
87f4a2713aSLionel Sambuc   --ci1;
88f4a2713aSLionel Sambuc }
89f4a2713aSLionel Sambuc 
90f4a2713aSLionel Sambuc // <rdar://problem/7958272>
t7(double _Complex c)91f4a2713aSLionel Sambuc double t7(double _Complex c) {
92f4a2713aSLionel Sambuc   return __builtin_fabs(__real__(c));
93f4a2713aSLionel Sambuc }
94f4a2713aSLionel Sambuc 
t8()95f4a2713aSLionel Sambuc void t8() {
96f4a2713aSLionel Sambuc   __complex__ int *x = &(__complex__ int){1};
97f4a2713aSLionel Sambuc }
98f4a2713aSLionel Sambuc 
99f4a2713aSLionel Sambuc const _Complex double test9const = 0;
test9func()100f4a2713aSLionel Sambuc _Complex double test9func() { return test9const; }
101*0a6a1f1dSLionel Sambuc 
102*0a6a1f1dSLionel Sambuc // D6217
t91()103*0a6a1f1dSLionel Sambuc void t91() {
104*0a6a1f1dSLionel Sambuc   // Check for proper type promotion of conditional expression
105*0a6a1f1dSLionel Sambuc   char c[(int)(sizeof(typeof((0 ? 2.0f : (_Complex double) 2.0f))) - sizeof(_Complex double))];
106*0a6a1f1dSLionel Sambuc   // Check for proper codegen
107*0a6a1f1dSLionel Sambuc   (0 ? 2.0f : (_Complex double) 2.0f);
108*0a6a1f1dSLionel Sambuc }
109*0a6a1f1dSLionel Sambuc 
t92()110*0a6a1f1dSLionel Sambuc void t92() {
111*0a6a1f1dSLionel Sambuc   // Check for proper type promotion of conditional expression
112*0a6a1f1dSLionel Sambuc   char c[(int)(sizeof(typeof((0 ? (_Complex double) 2.0f : 2.0f))) - sizeof(_Complex double))];
113*0a6a1f1dSLionel Sambuc   // Check for proper codegen
114*0a6a1f1dSLionel Sambuc   (0 ? (_Complex double) 2.0f : 2.0f);
115*0a6a1f1dSLionel Sambuc }
116*0a6a1f1dSLionel Sambuc 
117