• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 semantic
152 // impact remains even if every 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 -### -ffast-math -fno-finite-math-only \
158 // RUN:     -fno-unsafe-math-optimizations -fmath-errno -c %s 2>&1 \
159 // RUN:   | FileCheck --check-prefix=CHECK-FAST-MATH %s
160 // CHECK-FAST-MATH: "-cc1"
161 // CHECK-FAST-MATH: "-ffast-math"
162 //
163 // RUN: %clang -### -ffast-math -fno-fast-math -c %s 2>&1 \
164 // RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH %s
165 // CHECK-NO-FAST-MATH: "-cc1"
166 // CHECK-NO-FAST-MATH-NOT: "-ffast-math"
167 //
168 // Check various means of disabling these flags, including disabling them after
169 // they've been enabled via an umbrella flag.
170 // RUN: %clang -### -fno-honor-infinities -fhonor-infinities -c %s 2>&1 \
171 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
172 // RUN: %clang -### -ffinite-math-only -fhonor-infinities -c %s 2>&1 \
173 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
174 // RUN: %clang -### -ffinite-math-only -fno-finite-math-only -c %s 2>&1 \
175 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
176 // RUN: %clang -### -ffast-math -fhonor-infinities -c %s 2>&1 \
177 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
178 // RUN: %clang -### -ffast-math -fno-finite-math-only -c %s 2>&1 \
179 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
180 // CHECK-NO-NO-INFS: "-cc1"
181 // CHECK-NO-NO-INFS-NOT: "-menable-no-infs"
182 // CHECK-NO-NO-INFS: "-o"
183 //
184 // RUN: %clang -### -fno-honor-nans -fhonor-nans -c %s 2>&1 \
185 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
186 // RUN: %clang -### -ffinite-math-only -fhonor-nans -c %s 2>&1 \
187 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
188 // RUN: %clang -### -ffinite-math-only -fno-finite-math-only -c %s 2>&1 \
189 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
190 // RUN: %clang -### -ffast-math -fhonor-nans -c %s 2>&1 \
191 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
192 // RUN: %clang -### -ffast-math -fno-finite-math-only -c %s 2>&1 \
193 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
194 // CHECK-NO-NO-NANS: "-cc1"
195 // CHECK-NO-NO-NANS-NOT: "-menable-no-nans"
196 // CHECK-NO-NO-NANS: "-o"
197 //
198 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
199 // RUN:     -fno-trapping-math -fno-associative-math -c %s 2>&1 \
200 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
201 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
202 // RUN:     -fno-trapping-math -fno-reciprocal-math -c %s 2>&1 \
203 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
204 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
205 // RUN:     -fno-trapping-math -fsigned-zeros -c %s 2>&1 \
206 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
207 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
208 // RUN:     -fno-trapping-math -ftrapping-math -c %s 2>&1 \
209 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
210 // RUN: %clang -### -funsafe-math-optimizations -fno-associative-math -c %s \
211 // RUN:   2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
212 // RUN: %clang -### -funsafe-math-optimizations -fno-reciprocal-math -c %s \
213 // RUN:   2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
214 // RUN: %clang -### -funsafe-math-optimizations -fsigned-zeros -c %s 2>&1 \
215 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
216 // RUN: %clang -### -funsafe-math-optimizations -ftrapping-math -c %s 2>&1 \
217 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
218 // RUN: %clang -### -funsafe-math-optimizations -fno-unsafe-math-optimizations \
219 // RUN:     -c %s 2>&1 \
220 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
221 // RUN: %clang -### -ffast-math -fno-associative-math -c %s 2>&1 \
222 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
223 // RUN: %clang -### -ffast-math -fno-reciprocal-math -c %s 2>&1 \
224 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
225 // RUN: %clang -### -ffast-math -fsigned-zeros -c %s 2>&1 \
226 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
227 // RUN: %clang -### -ffast-math -ftrapping-math -c %s 2>&1 \
228 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
229 // RUN: %clang -### -ffast-math -fno-unsafe-math-optimizations -c %s 2>&1 \
230 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
231 // CHECK-NO-UNSAFE-MATH: "-cc1"
232 // CHECK-NO-UNSAFE-MATH-NOT: "-menable-unsafe-fp-math"
233 // CHECK-NO-UNSAFE-MATH: "-o"
234