blob: 1212660e878dbfed17e67ee6852a271dcc1da7c3 [file] [log] [blame]
Eli Friedman5b088a12010-01-03 00:20:48 +00001// RUN: %clang_cc1 -emit-llvm-only %s
Gabor Greifbacfa022007-07-13 22:15:44 +00002
Gabor Greifb02d4b42007-07-13 23:40:27 +00003int main(void)
Gabor Greifbacfa022007-07-13 22:15:44 +00004{
5 double _Complex a = 5;
6 double _Complex b = 42;
7
Gabor Greifb02d4b42007-07-13 23:40:27 +00008 return a * b != b * a;
Gabor Greifbacfa022007-07-13 22:15:44 +00009}
Chris Lattner12b2be22007-08-10 17:02:59 +000010
11_Complex double bar(int);
12void test(_Complex double*);
Chris Lattnerfd90ac02007-08-23 23:49:47 +000013void takecomplex(_Complex double);
Chris Lattner12b2be22007-08-10 17:02:59 +000014
15void test2(int c) {
16 _Complex double X;
17 X = bar(1);
18 test(&X);
Chris Lattnerfd90ac02007-08-23 23:49:47 +000019 takecomplex(X);
Chris Lattner12b2be22007-08-10 17:02:59 +000020}
21
Chris Lattnerfd90ac02007-08-23 23:49:47 +000022_Complex double g1, g2;
Chris Lattner8ae3a9f2007-08-26 22:41:57 +000023_Complex float cf;
24double D;
Chris Lattnerfd90ac02007-08-23 23:49:47 +000025
26void test3() {
27 g1 = g1 + g2;
28 g1 = g1 - g2;
29 g1 = g1 * g2;
30 g1 = +-~g1;
Chris Lattner46f93d02007-08-24 21:20:17 +000031
32 double Gr = __real g1;
Chris Lattner8ae3a9f2007-08-26 22:41:57 +000033
Chris Lattner9cff1a92007-08-27 16:37:44 +000034 cf += D;
Eli Friedmanab3a8522009-03-28 01:22:36 +000035 // FIXME: Currently unsupported!
36 //D += cf;
Chris Lattner8ae3a9f2007-08-26 22:41:57 +000037 cf /= g1;
Chris Lattner9cff1a92007-08-27 16:37:44 +000038 g1 = g1 + D;
39 g1 = D + g1;
Chris Lattnerfd90ac02007-08-23 23:49:47 +000040}
Chris Lattner7da36f62007-10-30 22:53:42 +000041
Eli Friedman5b088a12010-01-03 00:20:48 +000042__complex__ int ci1, ci2;
43__complex__ short cs;
44int i;
45void test3int() {
46 ci1 = ci1 + ci2;
47 ci1 = ci1 - ci2;
48 ci1 = ci1 * ci2;
49 ci1 = +-~ci1;
50
51 i = __real ci1;
52
53 cs += i;
54 // FIXME: Currently unsupported!
55 //D += cf;
56 cs /= ci1;
57 ci1 = ci1 + i;
58 ci1 = i + ci1;
59}
60
Chris Lattner7da36f62007-10-30 22:53:42 +000061void t1() {
62 (__real__ cf) = 4.0;
63}
64
65void t2() {
66 (__imag__ cf) = 4.0;
67}
68
Chris Lattner9b2dc282008-04-04 16:54:41 +000069// PR1960
70void t3() {
71 __complex__ long long v = 2;
72}
73
Anders Carlssonad3d6912008-11-25 22:21:48 +000074// PR3131
75float _Complex t4();
76
77void t5() {
78 float _Complex x = t4();
79}
80
Eli Friedman5b088a12010-01-03 00:20:48 +000081void t6() {
82 g1++;
83 g1--;
84 ++g1;
85 --g1;
86 ci1++;
87 ci1--;
88 ++ci1;
89 --ci1;
90}
91
John McCallabd3a852010-05-07 22:08:54 +000092// <rdar://problem/7958272>
93double t7(double _Complex c) {
94 return __builtin_fabs(__real__(c));
95}
Eli Friedman43e890b2011-06-15 20:17:07 +000096
97void t8() {
98 __complex__ int *x = &(__complex__ int){1};
99}