FSF GCC merge 02/23/03
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / builtin-complex-1.c
blob46ab7c51c0fab6582bf257297c541a57fc019c92
1 /* Test for builtin conj, creal, cimag. */
2 /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
4 extern float _Complex conjf (float _Complex);
5 extern double _Complex conj (double _Complex);
6 extern long double _Complex conjl (long double _Complex);
8 extern float crealf (float _Complex);
9 extern double creal (double _Complex);
10 extern long double creall (long double _Complex);
12 extern float cimagf (float _Complex);
13 extern double cimag (double _Complex);
14 extern long double cimagl (long double _Complex);
16 extern void abort (void);
17 extern void exit (int);
19 extern void link_failure (void);
21 int
22 main (void)
24 /* For each type, test both runtime and compile time (constant folding)
25 optimization. */
26 volatile float _Complex fc = 1.0F + 2.0iF;
27 volatile double _Complex dc = 1.0 + 2.0i;
28 volatile long double _Complex ldc = 1.0L + 2.0iL;
29 /* Test floats. */
30 if (conjf (fc) != 1.0F - 2.0iF)
31 abort ();
32 if (__builtin_conjf (fc) != 1.0F - 2.0iF)
33 abort ();
34 if (conjf (1.0F + 2.0iF) != 1.0F - 2.0iF)
35 link_failure ();
36 if (__builtin_conjf (1.0F + 2.0iF) != 1.0F - 2.0iF)
37 link_failure ();
38 if (crealf (fc) != 1.0F)
39 abort ();
40 if (__builtin_crealf (fc) != 1.0F)
41 abort ();
42 if (crealf (1.0F + 2.0iF) != 1.0F)
43 link_failure ();
44 if (__builtin_crealf (1.0F + 2.0iF) != 1.0F)
45 link_failure ();
46 if (cimagf (fc) != 2.0F)
47 abort ();
48 if (__builtin_cimagf (fc) != 2.0F)
49 abort ();
50 if (cimagf (1.0F + 2.0iF) != 2.0F)
51 link_failure ();
52 if (__builtin_cimagf (1.0F + 2.0iF) != 2.0F)
53 link_failure ();
54 /* Test doubles. */
55 if (conj (dc) != 1.0 - 2.0i)
56 abort ();
57 if (__builtin_conj (dc) != 1.0 - 2.0i)
58 abort ();
59 if (conj (1.0 + 2.0i) != 1.0 - 2.0i)
60 link_failure ();
61 if (__builtin_conj (1.0 + 2.0i) != 1.0 - 2.0i)
62 link_failure ();
63 if (creal (dc) != 1.0)
64 abort ();
65 if (__builtin_creal (dc) != 1.0)
66 abort ();
67 if (creal (1.0 + 2.0i) != 1.0)
68 link_failure ();
69 if (__builtin_creal (1.0 + 2.0i) != 1.0)
70 link_failure ();
71 if (cimag (dc) != 2.0)
72 abort ();
73 if (__builtin_cimag (dc) != 2.0)
74 abort ();
75 if (cimag (1.0 + 2.0i) != 2.0)
76 link_failure ();
77 if (__builtin_cimag (1.0 + 2.0i) != 2.0)
78 link_failure ();
79 /* Test long doubles. */
80 if (conjl (ldc) != 1.0L - 2.0iL)
81 abort ();
82 if (__builtin_conjl (ldc) != 1.0L - 2.0iL)
83 abort ();
84 if (conjl (1.0L + 2.0iL) != 1.0L - 2.0iL)
85 link_failure ();
86 if (__builtin_conjl (1.0L + 2.0iL) != 1.0L - 2.0iL)
87 link_failure ();
88 if (creall (ldc) != 1.0L)
89 abort ();
90 if (__builtin_creall (ldc) != 1.0L)
91 abort ();
92 if (creall (1.0L + 2.0iL) != 1.0L)
93 link_failure ();
94 if (__builtin_creall (1.0L + 2.0iL) != 1.0L)
95 link_failure ();
96 if (cimagl (ldc) != 2.0L)
97 abort ();
98 if (__builtin_cimagl (ldc) != 2.0L)
99 abort ();
100 if (cimagl (1.0L + 2.0iL) != 2.0L)
101 link_failure ();
102 if (__builtin_cimagl (1.0L + 2.0iL) != 2.0L)
103 link_failure ();
104 exit (0);
107 /* All the above cases should have been optimized to something else,
108 even if not optimizing (unless -fno-builtin was specified). So any
109 remaining calls to the original functions should abort. */
111 static float _Complex
112 conjf (float _Complex z)
114 abort ();
117 static double _Complex
118 conj (double _Complex z)
120 abort ();
123 static long double _Complex
124 conjl (long double _Complex z)
126 abort ();
129 static float
130 crealf (float _Complex z)
132 abort ();
135 static double
136 creal (double _Complex z)
138 abort ();
141 static long double
142 creall (long double _Complex z)
144 abort ();
147 static float
148 cimagf (float _Complex z)
150 abort ();
153 static double
154 cimag (double _Complex z)
156 abort ();
159 static long double
160 cimagl (long double _Complex z)
162 abort ();
165 /* When optimizing, all the constant cases should have been
166 constant folded, so no calls to link_failure should remain. In any case,
167 link_failure should not be called. */
169 #ifndef __OPTIMIZE__
170 void
171 link_failure (void)
173 abort ();
175 #endif