1 | // RUN: %clang_cc1 %s -O1 -emit-llvm -o - | FileCheck %s |
2 | // rdar://8315199 |
3 | |
4 | /* Test for builtin conj, creal, cimag. */ |
5 | /* Origin: Joseph Myers <jsm28@cam.ac.uk> */ |
6 | |
7 | extern float _Complex conjf (float _Complex); |
8 | extern double _Complex conj (double _Complex); |
9 | extern long double _Complex conjl (long double _Complex); |
10 | |
11 | extern float crealf (float _Complex); |
12 | extern double creal (double _Complex); |
13 | extern long double creall (long double _Complex); |
14 | |
15 | extern float cimagf (float _Complex); |
16 | extern double cimag (double _Complex); |
17 | extern long double cimagl (long double _Complex); |
18 | |
19 | extern void abort (void); |
20 | extern void link_error (void); |
21 | |
22 | int |
23 | main () |
24 | { |
25 | /* For each type, test both runtime and compile time (constant folding) |
26 | optimization. */ |
27 | volatile float _Complex fc = 1.0F + 2.0iF; |
28 | volatile double _Complex dc = 1.0 + 2.0i; |
29 | volatile long double _Complex ldc = 1.0L + 2.0iL; |
30 | /* Test floats. */ |
31 | if (__builtin_conjf (fc) != 1.0F - 2.0iF) |
32 | abort (); |
33 | if (__builtin_conjf (1.0F + 2.0iF) != 1.0F - 2.0iF) |
34 | link_error (); |
35 | if (__builtin_crealf (fc) != 1.0F) |
36 | abort (); |
37 | if (__builtin_crealf (1.0F + 2.0iF) != 1.0F) |
38 | link_error (); |
39 | if (__builtin_cimagf (fc) != 2.0F) |
40 | abort (); |
41 | if (__builtin_cimagf (1.0F + 2.0iF) != 2.0F) |
42 | link_error (); |
43 | /* Test doubles. */ |
44 | if (__builtin_conj (dc) != 1.0 - 2.0i) |
45 | abort (); |
46 | if (__builtin_conj (1.0 + 2.0i) != 1.0 - 2.0i) |
47 | link_error (); |
48 | if (__builtin_creal (dc) != 1.0) |
49 | abort (); |
50 | if (__builtin_creal (1.0 + 2.0i) != 1.0) |
51 | link_error (); |
52 | if (__builtin_cimag (dc) != 2.0) |
53 | abort (); |
54 | if (__builtin_cimag (1.0 + 2.0i) != 2.0) |
55 | link_error (); |
56 | /* Test long doubles. */ |
57 | if (__builtin_conjl (ldc) != 1.0L - 2.0iL) |
58 | abort (); |
59 | if (__builtin_conjl (1.0L + 2.0iL) != 1.0L - 2.0iL) |
60 | link_error (); |
61 | if (__builtin_creall (ldc) != 1.0L) |
62 | abort (); |
63 | if (__builtin_creall (1.0L + 2.0iL) != 1.0L) |
64 | link_error (); |
65 | if (__builtin_cimagl (ldc) != 2.0L) |
66 | abort (); |
67 | if (__builtin_cimagl (1.0L + 2.0iL) != 2.0L) |
68 | link_error (); |
69 | } |
70 | |
71 | // CHECK-NOT: link_error |
72 | |