]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/Driver/fast-math.c
Vendor import of clang trunk r300422:
[FreeBSD/FreeBSD.git] / test / Driver / fast-math.c
1 // Test that the GCC fast-math floating point flags get lowered to the correct
2 // permutation of Clang frontend flags. This is non-trivial for a few reasons.
3 // First, the GCC flags have many different and surprising effects. Second,
4 // LLVM only supports three switches which is more coarse grained than GCC's
5 // support.
6 //
7 // Both of them use gcc driver for as.
8 // REQUIRES: clang-driver
9 //
10 // RUN: %clang -### -fno-honor-infinities -c %s 2>&1 \
11 // RUN:   | FileCheck --check-prefix=CHECK-NO-INFS %s
12 // infinites [sic] is a supported alternative spelling of infinities.
13 // RUN: %clang -### -fno-honor-infinites -c %s 2>&1 \
14 // RUN:   | FileCheck --check-prefix=CHECK-NO-INFS %s
15 // CHECK-NO-INFS: "-cc1"
16 // CHECK-NO-INFS: "-menable-no-infs"
17 //
18 // RUN: %clang -### -fno-fast-math -fno-honor-infinities -c %s 2>&1 \
19 // RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH-NO-INFS %s
20 // CHECK-NO-FAST-MATH-NO-INFS: "-cc1"
21 // CHECK-NO-FAST-MATH-NO-INFS: "-menable-no-infs"
22 //
23 // RUN: %clang -### -fno-honor-infinities -fno-fast-math -c %s 2>&1 \
24 // RUN:   | FileCheck --check-prefix=CHECK-NO-INFS-NO-FAST-MATH %s
25 // CHECK-NO-INFS-NO-FAST-MATH: "-cc1"
26 // CHECK-NO-INFS-NO-FAST-MATH-NOT: "-menable-no-infs"
27 //
28 // RUN: %clang -### -fno-signed-zeros -c %s 2>&1 \
29 // RUN:   | FileCheck --check-prefix=CHECK-NO-SIGNED-ZEROS %s
30 // CHECK-NO-SIGNED-ZEROS: "-cc1"
31 // CHECK-NO-SIGNED-ZEROS: "-fno-signed-zeros"
32 //
33 // RUN: %clang -### -fno-fast-math -fno-signed-zeros -c %s 2>&1 \
34 // RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH-NO-SIGNED-ZEROS %s
35 // CHECK-NO-FAST-MATH-NO-SIGNED-ZEROS: "-cc1"
36 // CHECK-NO-FAST-MATH-NO-SIGNED-ZEROS: "-fno-signed-zeros"
37 //
38 // RUN: %clang -### -fno-signed-zeros -fno-fast-math -c %s 2>&1 \
39 // RUN:   | FileCheck --check-prefix=CHECK-NO-SIGNED-ZEROS-NO-FAST-MATH %s
40 // CHECK-NO-SIGNED-ZEROS-NO-FAST-MATH: "-cc1"
41 // CHECK-NO-SIGNED-ZEROS-NO-FAST-MATH-NOT: "-fno-signed-zeros"
42 //
43 // RUN: %clang -### -freciprocal-math -c %s 2>&1 \
44 // RUN:   | FileCheck --check-prefix=CHECK-RECIPROCAL-MATH %s
45 // CHECK-RECIPROCAL-MATH: "-cc1"
46 // CHECK-RECIPROCAL-MATH: "-freciprocal-math"
47 //
48 // RUN: %clang -### -fno-fast-math -freciprocal-math -c %s 2>&1 \
49 // RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH-RECIPROCAL-MATH %s
50 // CHECK-NO-FAST-MATH-RECIPROCAL-MATH: "-cc1"
51 // CHECK-NO-FAST-MATH-RECIPROCAL-MATH: "-freciprocal-math"
52 //
53 // RUN: %clang -### -freciprocal-math -fno-fast-math -c %s 2>&1 \
54 // RUN:   | FileCheck --check-prefix=CHECK-RECIPROCAL-MATH-NO-FAST-MATH %s
55 // CHECK-RECIPROCAL-MATH-NO-FAST-MATH: "-cc1"
56 // CHECK-RECIPROCAL-MATH-NO-FAST-MATH-NOT: "-freciprocal-math"
57 //
58 // RUN: %clang -### -fno-honor-nans -c %s 2>&1 \
59 // RUN:   | FileCheck --check-prefix=CHECK-NO-NANS %s
60 // CHECK-NO-NANS: "-cc1"
61 // CHECK-NO-NANS: "-menable-no-nans"
62 //
63 // RUN: %clang -### -fno-fast-math -fno-honor-nans -c %s 2>&1 \
64 // RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH-NO-NANS %s
65 // CHECK-NO-FAST-MATH-NO-NANS: "-cc1"
66 // CHECK-NO-FAST-MATH-NO-NANS: "-menable-no-nans"
67 //
68 // RUN: %clang -### -fno-honor-nans -fno-fast-math -c %s 2>&1 \
69 // RUN:   | FileCheck --check-prefix=CHECK-NO-NANS-NO-FAST-MATH %s
70 // CHECK-NO-NANS-NO-FAST-MATH: "-cc1"
71 // CHECK-NO-NANS-NO-FAST-MATH-NOT: "-menable-no-nans"
72 //
73 // RUN: %clang -### -fmath-errno -c %s 2>&1 \
74 // RUN:   | FileCheck --check-prefix=CHECK-MATH-ERRNO %s
75 // CHECK-MATH-ERRNO: "-cc1"
76 // CHECK-MATH-ERRNO: "-fmath-errno"
77 //
78 // RUN: %clang -### -fmath-errno -fno-math-errno -c %s 2>&1 \
79 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
80 // CHECK-NO-MATH-ERRNO: "-cc1"
81 // CHECK-NO-MATH-ERRNO-NOT: "-fmath-errno"
82 //
83 // Target defaults for -fmath-errno (reusing the above checks).
84 // RUN: %clang -### -target i686-unknown-linux -c %s 2>&1 \
85 // RUN:   | FileCheck --check-prefix=CHECK-MATH-ERRNO %s
86 // RUN: %clang -### -target i686-apple-darwin -c %s 2>&1 \
87 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
88 // RUN: %clang -### -target x86_64-unknown-freebsd -c %s 2>&1 \
89 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
90 // RUN: %clang -### -target x86_64-unknown-netbsd -c %s 2>&1 \
91 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
92 // RUN: %clang -### -target x86_64-unknown-openbsd -c %s 2>&1 \
93 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
94 // RUN: %clang -### -target x86_64-unknown-dragonfly -c %s 2>&1 \
95 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
96 //
97 // Check that -ffast-math disables -fmath-errno, and -fno-fast-math merely
98 // preserves the target default. Also check various flag set operations between
99 // the two flags. (Resuses above checks.)
100 // RUN: %clang -### -ffast-math -c %s 2>&1 \
101 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
102 // RUN: %clang -### -fmath-errno -ffast-math -c %s 2>&1 \
103 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
104 // RUN: %clang -### -ffast-math -fmath-errno -c %s 2>&1 \
105 // RUN:   | FileCheck --check-prefix=CHECK-MATH-ERRNO %s
106 // RUN: %clang -### -target i686-unknown-linux -fno-fast-math -c %s 2>&1 \
107 // RUN:   | FileCheck --check-prefix=CHECK-MATH-ERRNO %s
108 // RUN: %clang -### -target i686-unknown-linux -fno-math-errno -fno-fast-math -c %s 2>&1 \
109 // RUN:   | FileCheck --check-prefix=CHECK-MATH-ERRNO %s
110 // RUN: %clang -### -target i686-apple-darwin -fno-fast-math -c %s 2>&1 \
111 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
112 // RUN: %clang -### -target i686-apple-darwin -fno-math-errno -fno-fast-math -c %s 2>&1 \
113 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
114 // RUN: %clang -### -fno-fast-math -fno-math-errno -c %s 2>&1 \
115 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
116 //
117 // RUN: %clang -### -fno-math-errno -fassociative-math -freciprocal-math \
118 // RUN:     -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \
119 // RUN:   | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s
120 // CHECK-UNSAFE-MATH: "-cc1"
121 // CHECK-UNSAFE-MATH: "-menable-unsafe-fp-math"
122 //
123 // RUN: %clang -### -fno-fast-math -fno-math-errno -fassociative-math -freciprocal-math \
124 // RUN:     -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \
125 // RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH-UNSAFE-MATH %s
126 // CHECK-NO-FAST-MATH-UNSAFE-MATH: "-cc1"
127 // CHECK-NO-FAST-MATH-UNSAFE-MATH: "-menable-unsafe-fp-math"
128 //
129 // RUN: %clang -### -fno-fast-math -fno-math-errno -fassociative-math -freciprocal-math \
130 // RUN:     -fno-fast-math -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \
131 // RUN:   | FileCheck --check-prefix=CHECK-UNSAFE-MATH-NO-FAST-MATH %s
132 // CHECK-UNSAFE-MATH-NO-FAST-MATH: "-cc1"
133 // CHECK-UNSAFE-MATH-NO-FAST-MATH-NOT: "-menable-unsafe-fp-math"
134 //
135 // Check that various umbrella flags also enable these frontend options.
136 // RUN: %clang -### -ffast-math -c %s 2>&1 \
137 // RUN:   | FileCheck --check-prefix=CHECK-NO-INFS %s
138 // RUN: %clang -### -ffast-math -c %s 2>&1 \
139 // RUN:   | FileCheck --check-prefix=CHECK-NO-NANS %s
140 // RUN: %clang -### -ffast-math -c %s 2>&1 \
141 // RUN:   | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s
142 // RUN: %clang -### -ffinite-math-only -c %s 2>&1 \
143 // RUN:   | FileCheck --check-prefix=CHECK-NO-INFS %s
144 // RUN: %clang -### -ffinite-math-only -c %s 2>&1 \
145 // RUN:   | FileCheck --check-prefix=CHECK-NO-NANS %s
146 // RUN: %clang -### -funsafe-math-optimizations -fno-math-errno -c %s 2>&1 \
147 // RUN:   | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s
148 //
149 // One umbrella flag is *really* weird and also changes the semantics of the
150 // program by adding a special preprocessor macro. Check that the frontend flag
151 // modeling this semantic change is provided. Also check that the flag is not
152 // present if any of the optimization is disabled.
153 // RUN: %clang -### -ffast-math -c %s 2>&1 \
154 // RUN:   | FileCheck --check-prefix=CHECK-FAST-MATH %s
155 // RUN: %clang -### -fno-fast-math -ffast-math -c %s 2>&1 \
156 // RUN:   | FileCheck --check-prefix=CHECK-FAST-MATH %s
157 // RUN: %clang -### -funsafe-math-optimizations -ffinite-math-only \
158 // RUN:     -fno-math-errno -ffp-contract=fast -c %s 2>&1 \
159 // RUN:   | FileCheck --check-prefix=CHECK-FAST-MATH %s
160 // RUN: %clang -### -fno-honor-infinities -fno-honor-nans -fno-math-errno \
161 // RUN:     -fassociative-math -freciprocal-math -fno-signed-zeros \
162 // RUN:     -fno-trapping-math -ffp-contract=fast -c %s 2>&1 \
163 // RUN:   | FileCheck --check-prefix=CHECK-FAST-MATH %s
164 // CHECK-FAST-MATH: "-cc1"
165 // CHECK-FAST-MATH: "-ffast-math"
166 // CHECK-FAST-MATH: "-ffinite-math-only"
167 //
168 // RUN: %clang -### -ffast-math -fno-fast-math -c %s 2>&1 \
169 // RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH %s
170 // RUN: %clang -### -ffast-math -fno-finite-math-only -c %s 2>&1 \
171 // RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH %s
172 // RUN: %clang -### -ffast-math -fno-unsafe-math-optimizations -c %s 2>&1 \
173 // RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH %s
174 // RUN: %clang -### -ffast-math -fmath-errno -c %s 2>&1 \
175 // RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH %s
176 // CHECK-NO-FAST-MATH: "-cc1"
177 // CHECK-NO-FAST-MATH-NOT: "-ffast-math"
178 //
179 // Check various means of disabling these flags, including disabling them after
180 // they've been enabled via an umbrella flag.
181 // RUN: %clang -### -fno-honor-infinities -fhonor-infinities -c %s 2>&1 \
182 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
183 // RUN: %clang -### -ffinite-math-only -fhonor-infinities -c %s 2>&1 \
184 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
185 // RUN: %clang -### -ffinite-math-only -fno-finite-math-only -c %s 2>&1 \
186 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
187 // RUN: %clang -### -ffast-math -fhonor-infinities -c %s 2>&1 \
188 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
189 // RUN: %clang -### -ffast-math -fno-finite-math-only -c %s 2>&1 \
190 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
191 // CHECK-NO-NO-INFS: "-cc1"
192 // CHECK-NO-NO-INFS-NOT: "-menable-no-infs"
193 // CHECK-NO-NO-INFS-NOT: "-ffinite-math-only"
194 // CHECK-NO-NO-INFS: "-o"
195 //
196 // RUN: %clang -### -fno-honor-nans -fhonor-nans -c %s 2>&1 \
197 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
198 // RUN: %clang -### -ffinite-math-only -fhonor-nans -c %s 2>&1 \
199 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
200 // RUN: %clang -### -ffinite-math-only -fno-finite-math-only -c %s 2>&1 \
201 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
202 // RUN: %clang -### -ffast-math -fhonor-nans -c %s 2>&1 \
203 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
204 // RUN: %clang -### -ffast-math -fno-finite-math-only -c %s 2>&1 \
205 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
206 // CHECK-NO-NO-NANS: "-cc1"
207 // CHECK-NO-NO-NANS-NOT: "-menable-no-nans"
208 // CHECK-NO-NO-NANS-NOT: "-ffinite-math-only"
209 // CHECK-NO-NO-NANS: "-o"
210 //
211 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
212 // RUN:     -fno-trapping-math -fno-associative-math -c %s 2>&1 \
213 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
214 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
215 // RUN:     -fno-trapping-math -fno-reciprocal-math -c %s 2>&1 \
216 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
217 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
218 // RUN:     -fno-trapping-math -fsigned-zeros -c %s 2>&1 \
219 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
220 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
221 // RUN:     -fno-trapping-math -ftrapping-math -c %s 2>&1 \
222 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
223 // RUN: %clang -### -funsafe-math-optimizations -fno-associative-math -c %s \
224 // RUN:   2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
225 // RUN: %clang -### -funsafe-math-optimizations -fno-reciprocal-math -c %s \
226 // RUN:   2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
227 // RUN: %clang -### -funsafe-math-optimizations -fsigned-zeros -c %s 2>&1 \
228 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
229 // RUN: %clang -### -funsafe-math-optimizations -ftrapping-math -c %s 2>&1 \
230 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
231 // RUN: %clang -### -funsafe-math-optimizations -fno-unsafe-math-optimizations \
232 // RUN:     -c %s 2>&1 \
233 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
234 // RUN: %clang -### -ffast-math -fno-associative-math -c %s 2>&1 \
235 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
236 // RUN: %clang -### -ffast-math -fno-reciprocal-math -c %s 2>&1 \
237 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
238 // RUN: %clang -### -ffast-math -fsigned-zeros -c %s 2>&1 \
239 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
240 // RUN: %clang -### -ffast-math -ftrapping-math -c %s 2>&1 \
241 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
242 // RUN: %clang -### -ffast-math -fno-unsafe-math-optimizations -c %s 2>&1 \
243 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
244 // CHECK-NO-UNSAFE-MATH: "-cc1"
245 // CHECK-NO-UNSAFE-MATH-NOT: "-menable-unsafe-fp-math"
246 // CHECK-NO-UNSAFE-MATH: "-o"
247 //
248 // RUN: %clang -### -ftrapping-math -fno-trapping-math -c %s 2>&1 \
249 // RUN:   | FileCheck --check-prefix=CHECK-NO-TRAPPING-MATH %s
250 // CHECK-NO-TRAPPING-MATH: "-fno-trapping-math"