Clang Project

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