xref: /minix3/external/bsd/llvm/dist/clang/test/Driver/fast-math.c (revision 5ba302fdeaa9e153d58b5dcaef42d660aedee92e)
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 // CHECK-NO-INFS: "-cc1"
13 // CHECK-NO-INFS: "-menable-no-infs"
14 //
15 // RUN: %clang -### -fno-fast-math -fno-honor-infinities -c %s 2>&1 \
16 // RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH-NO-INFS %s
17 // CHECK-NO-FAST-MATH-NO-INFS: "-cc1"
18 // CHECK-NO-FAST-MATH-NO-INFS: "-menable-no-infs"
19 //
20 // RUN: %clang -### -fno-honor-infinities -fno-fast-math -c %s 2>&1 \
21 // RUN:   | FileCheck --check-prefix=CHECK-NO-INFS-NO-FAST-MATH %s
22 // CHECK-NO-INFS-NO-FAST-MATH: "-cc1"
23 // CHECK-NO-INFS-NO-FAST-MATH-NOT: "-menable-no-infs"
24 //
25 // RUN: %clang -### -fno-honor-nans -c %s 2>&1 \
26 // RUN:   | FileCheck --check-prefix=CHECK-NO-NANS %s
27 // CHECK-NO-NANS: "-cc1"
28 // CHECK-NO-NANS: "-menable-no-nans"
29 //
30 // RUN: %clang -### -fno-fast-math -fno-honor-nans -c %s 2>&1 \
31 // RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH-NO-NANS %s
32 // CHECK-NO-FAST-MATH-NO-NANS: "-cc1"
33 // CHECK-NO-FAST-MATH-NO-NANS: "-menable-no-nans"
34 //
35 // RUN: %clang -### -fno-honor-nans -fno-fast-math -c %s 2>&1 \
36 // RUN:   | FileCheck --check-prefix=CHECK-NO-NANS-NO-FAST-MATH %s
37 // CHECK-NO-NANS-NO-FAST-MATH: "-cc1"
38 // CHECK-NO-NANS-NO-FAST-MATH-NOT: "-menable-no-nans"
39 //
40 // RUN: %clang -### -fmath-errno -c %s 2>&1 \
41 // RUN:   | FileCheck --check-prefix=CHECK-MATH-ERRNO %s
42 // CHECK-MATH-ERRNO: "-cc1"
43 // CHECK-MATH-ERRNO: "-fmath-errno"
44 //
45 // RUN: %clang -### -fmath-errno -fno-math-errno -c %s 2>&1 \
46 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
47 // CHECK-NO-MATH-ERRNO: "-cc1"
48 // CHECK-NO-MATH-ERRNO-NOT: "-fmath-errno"
49 //
50 // Target defaults for -fmath-errno (reusing the above checks).
51 // RUN: %clang -### -target i686-unknown-linux -c %s 2>&1 \
52 // RUN:   | FileCheck --check-prefix=CHECK-MATH-ERRNO %s
53 // RUN: %clang -### -target i686-apple-darwin -c %s 2>&1 \
54 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
55 // RUN: %clang -### -target x86_64-unknown-freebsd -c %s 2>&1 \
56 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
57 // RUN: %clang -### -target x86_64-unknown-netbsd -c %s 2>&1 \
58 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
59 // RUN: %clang -### -target x86_64-unknown-openbsd -c %s 2>&1 \
60 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
61 // RUN: %clang -### -target x86_64-unknown-dragonfly -c %s 2>&1 \
62 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
63 //
64 // Check that -ffast-math disables -fmath-errno, and -fno-fast-math merely
65 // preserves the target default. Also check various flag set operations between
66 // the two flags. (Resuses above checks.)
67 // RUN: %clang -### -ffast-math -c %s 2>&1 \
68 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
69 // RUN: %clang -### -fmath-errno -ffast-math -c %s 2>&1 \
70 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
71 // RUN: %clang -### -ffast-math -fmath-errno -c %s 2>&1 \
72 // RUN:   | FileCheck --check-prefix=CHECK-MATH-ERRNO %s
73 // RUN: %clang -### -target i686-unknown-linux -fno-fast-math -c %s 2>&1 \
74 // RUN:   | FileCheck --check-prefix=CHECK-MATH-ERRNO %s
75 // RUN: %clang -### -target i686-unknown-linux -fno-math-errno -fno-fast-math -c %s 2>&1 \
76 // RUN:   | FileCheck --check-prefix=CHECK-MATH-ERRNO %s
77 // RUN: %clang -### -target i686-apple-darwin -fno-fast-math -c %s 2>&1 \
78 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
79 // RUN: %clang -### -target i686-apple-darwin -fno-math-errno -fno-fast-math -c %s 2>&1 \
80 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
81 // RUN: %clang -### -fno-fast-math -fno-math-errno -c %s 2>&1 \
82 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
83 //
84 // RUN: %clang -### -fno-math-errno -fassociative-math -freciprocal-math \
85 // RUN:     -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \
86 // RUN:   | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s
87 // CHECK-UNSAFE-MATH: "-cc1"
88 // CHECK-UNSAFE-MATH: "-menable-unsafe-fp-math"
89 //
90 // RUN: %clang -### -fno-fast-math -fno-math-errno -fassociative-math -freciprocal-math \
91 // RUN:     -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \
92 // RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH-UNSAFE-MATH %s
93 // CHECK-NO-FAST-MATH-UNSAFE-MATH: "-cc1"
94 // CHECK-NO-FAST-MATH-UNSAFE-MATH: "-menable-unsafe-fp-math"
95 //
96 // RUN: %clang -### -fno-fast-math -fno-math-errno -fassociative-math -freciprocal-math \
97 // RUN:     -fno-fast-math -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \
98 // RUN:   | FileCheck --check-prefix=CHECK-UNSAFE-MATH-NO-FAST-MATH %s
99 // CHECK-UNSAFE-MATH-NO-FAST-MATH: "-cc1"
100 // CHECK-UNSAFE-MATH-NO-FAST-MATH-NOT: "-menable-unsafe-fp-math"
101 //
102 // Check that various umbrella flags also enable these frontend options.
103 // RUN: %clang -### -ffast-math -c %s 2>&1 \
104 // RUN:   | FileCheck --check-prefix=CHECK-NO-INFS %s
105 // RUN: %clang -### -ffast-math -c %s 2>&1 \
106 // RUN:   | FileCheck --check-prefix=CHECK-NO-NANS %s
107 // RUN: %clang -### -ffast-math -c %s 2>&1 \
108 // RUN:   | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s
109 // RUN: %clang -### -ffinite-math-only -c %s 2>&1 \
110 // RUN:   | FileCheck --check-prefix=CHECK-NO-INFS %s
111 // RUN: %clang -### -ffinite-math-only -c %s 2>&1 \
112 // RUN:   | FileCheck --check-prefix=CHECK-NO-NANS %s
113 // RUN: %clang -### -funsafe-math-optimizations -fno-math-errno -c %s 2>&1 \
114 // RUN:   | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s
115 //
116 // One umbrella flag is *really* weird and also changes the semantics of the
117 // program by adding a special preprocessor macro. Check that the frontend flag
118 // modeling this semantic change is provided. Also check that the semantic
119 // impact remains even if every optimization is disabled.
120 // RUN: %clang -### -ffast-math -c %s 2>&1 \
121 // RUN:   | FileCheck --check-prefix=CHECK-FAST-MATH %s
122 // RUN: %clang -### -fno-fast-math -ffast-math -c %s 2>&1 \
123 // RUN:   | FileCheck --check-prefix=CHECK-FAST-MATH %s
124 // RUN: %clang -### -ffast-math -fno-finite-math-only \
125 // RUN:     -fno-unsafe-math-optimizations -fmath-errno -c %s 2>&1 \
126 // RUN:   | FileCheck --check-prefix=CHECK-FAST-MATH %s
127 // CHECK-FAST-MATH: "-cc1"
128 // CHECK-FAST-MATH: "-ffast-math"
129 //
130 // RUN: %clang -### -ffast-math -fno-fast-math -c %s 2>&1 \
131 // RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH %s
132 // CHECK-NO-FAST-MATH: "-cc1"
133 // CHECK-NO-FAST-MATH-NOT: "-ffast-math"
134 //
135 // Check various means of disabling these flags, including disabling them after
136 // they've been enabled via an umbrella flag.
137 // RUN: %clang -### -fno-honor-infinities -fhonor-infinities -c %s 2>&1 \
138 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
139 // RUN: %clang -### -ffinite-math-only -fhonor-infinities -c %s 2>&1 \
140 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
141 // RUN: %clang -### -ffinite-math-only -fno-finite-math-only -c %s 2>&1 \
142 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
143 // RUN: %clang -### -ffast-math -fhonor-infinities -c %s 2>&1 \
144 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
145 // RUN: %clang -### -ffast-math -fno-finite-math-only -c %s 2>&1 \
146 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
147 // CHECK-NO-NO-INFS: "-cc1"
148 // CHECK-NO-NO-INFS-NOT: "-menable-no-infs"
149 // CHECK-NO-NO-INFS: "-o"
150 //
151 // RUN: %clang -### -fno-honor-nans -fhonor-nans -c %s 2>&1 \
152 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
153 // RUN: %clang -### -ffinite-math-only -fhonor-nans -c %s 2>&1 \
154 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
155 // RUN: %clang -### -ffinite-math-only -fno-finite-math-only -c %s 2>&1 \
156 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
157 // RUN: %clang -### -ffast-math -fhonor-nans -c %s 2>&1 \
158 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
159 // RUN: %clang -### -ffast-math -fno-finite-math-only -c %s 2>&1 \
160 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
161 // CHECK-NO-NO-NANS: "-cc1"
162 // CHECK-NO-NO-NANS-NOT: "-menable-no-nans"
163 // CHECK-NO-NO-NANS: "-o"
164 //
165 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
166 // RUN:     -fno-trapping-math -fno-associative-math -c %s 2>&1 \
167 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
168 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
169 // RUN:     -fno-trapping-math -fno-reciprocal-math -c %s 2>&1 \
170 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
171 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
172 // RUN:     -fno-trapping-math -fsigned-zeros -c %s 2>&1 \
173 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
174 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
175 // RUN:     -fno-trapping-math -ftrapping-math -c %s 2>&1 \
176 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
177 // RUN: %clang -### -funsafe-math-optimizations -fno-associative-math -c %s \
178 // RUN:   2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
179 // RUN: %clang -### -funsafe-math-optimizations -fno-reciprocal-math -c %s \
180 // RUN:   2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
181 // RUN: %clang -### -funsafe-math-optimizations -fsigned-zeros -c %s 2>&1 \
182 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
183 // RUN: %clang -### -funsafe-math-optimizations -ftrapping-math -c %s 2>&1 \
184 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
185 // RUN: %clang -### -funsafe-math-optimizations -fno-unsafe-math-optimizations \
186 // RUN:     -c %s 2>&1 \
187 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
188 // RUN: %clang -### -ffast-math -fno-associative-math -c %s 2>&1 \
189 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
190 // RUN: %clang -### -ffast-math -fno-reciprocal-math -c %s 2>&1 \
191 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
192 // RUN: %clang -### -ffast-math -fsigned-zeros -c %s 2>&1 \
193 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
194 // RUN: %clang -### -ffast-math -ftrapping-math -c %s 2>&1 \
195 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
196 // RUN: %clang -### -ffast-math -fno-unsafe-math-optimizations -c %s 2>&1 \
197 // RUN:   | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
198 // CHECK-NO-UNSAFE-MATH: "-cc1"
199 // CHECK-NO-UNSAFE-MATH-NOT: "-menable-unsafe-fp-math"
200 // CHECK-NO-UNSAFE-MATH: "-o"
201