xref: /llvm-project/clang/test/Driver/fp-contract.c (revision 97839a8862bde89f07060ff0aa4993a868a501cd)
1 // Test that -ffp-contract is set to the right value when combined with
2 // the options -ffast-math, -fno-fast-math, funsafe-math-optimizations,
3 // fno-unsafe-math-optimizations.
4 
5 // These warning checks are above the run lines because the warning is reported
6 // before the drive options that are checked below the run lines.
7 // WARN_FM_OFF: warning: overriding '-ffast-math' option with '-ffp-contract=off'
8 // WARN_FM_ON: warning: overriding '-ffast-math' option with '-ffp-contract=on'
9 // WARN_FM_FHP: warning: overriding '-ffast-math' option with '-ffp-contract=fast-honor-pragmas'
10 // WARN_UM_OFF: warning: overriding '-funsafe-math-optimizations' option with '-ffp-contract=off'
11 // WARN_UM_ON: warning: overriding '-funsafe-math-optimizations' option with '-ffp-contract=on'
12 
13 // ffast-math, fno-fast-math
14 // RUN: %clang -### -ffast-math -c %s 2>&1  \
15 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
16 // CHECK-FPC-FAST:     "-ffp-contract=fast"
17 
18 // RUN: %clang -### -fno-fast-math -c %s 2>&1 \
19 // RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
20 
21 // RUN: %clang -### -ffast-math -ffp-contract=on -c %s 2>&1 \
22 // RUN:   | FileCheck --check-prefixes=CHECK-FPC-ON,WARN_FM_ON %s
23 // CHECK-FPC-ON:       "-ffp-contract=on"
24 
25 // RUN: %clang -### -ffast-math -ffp-contract=off -c %s 2>&1 \
26 // RUN:   | FileCheck --check-prefixes=CHECK-FPC-OFF,WARN_FM_OFF %s
27 // CHECK-FPC-OFF:      "-ffp-contract=off"
28 
29 // RUN: %clang -### -Werror -ffast-math -ffp-contract=fast -c %s 2>&1 \
30 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
31 
32 // RUN: %clang -### -ffast-math -ffp-contract=fast-honor-pragmas -c %s 2>&1 \
33 // RUN:   | FileCheck --check-prefixes=CHECK-FPC-FAST-HONOR,WARN_FM_FHP %s
34 // CHECK-FPC-FAST-HONOR:     "-ffp-contract=fast-honor-pragmas"
35 
36 // RUN: %clang -### -Werror -ffp-contract=fast -ffast-math -c %s 2>&1 \
37 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
38 // RUN: %clang -### -Werror -ffp-contract=on -ffast-math -c %s 2>&1 \
39 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
40 // RUN: %clang -### -Werror -ffp-contract=off -ffast-math -c %s 2>&1 \
41 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
42 
43 // RUN: %clang -### -Werror -ffp-contract=fast -fno-fast-math -c %s 2>&1 \
44 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
45 // RUN: %clang -### -Werror -ffp-contract=on -fno-fast-math -c %s 2>&1 \
46 // RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
47 // RUN: %clang -### -Werror -ffp-contract=off -fno-fast-math -c %s 2>&1 \
48 // RUN:   | FileCheck --check-prefix=CHECK-FPC-OFF %s
49 
50 
51 // RUN: %clang -### -Werror -ffast-math -ffp-contract=fast -ffp-contract=on -c %s 2>&1 \
52 // RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
53 
54 // RUN: %clang -### -ffast-math -ffp-contract=on -ffp-contract=off -c %s 2>&1 \
55 // RUN:   | FileCheck --check-prefixes=CHECK-FPC-OFF,WARN_FM_ON %s
56 
57 // RUN: %clang -### -ffast-math -ffp-contract=on -ffp-contract=fast -c %s 2>&1 \
58 // RUN:   | FileCheck --check-prefixes=CHECK-FPC-FAST,WARN_FM_ON %s
59 
60 // RUN: %clang -### -ffast-math -ffp-contract=off -ffp-contract=on -c %s 2>&1 \
61 // RUN:   | FileCheck --check-prefixes=CHECK-FPC-ON,WARN_FM_OFF %s
62 
63 // RUN: %clang -### -ffast-math -ffp-contract=off -ffp-contract=fast \
64 // RUN: -c %s 2>&1 | FileCheck --check-prefixes=CHECK-FPC-FAST,WARN_FM_OFF %s
65 
66 // RUN: %clang -### -ffast-math -ffp-contract=on -fno-fast-math -c %s 2>&1 \
67 // RUN:   | FileCheck --check-prefixes=CHECK-FPC-ON,WARN_FM_ON %s
68 
69 // RUN: %clang -### -ffast-math -ffp-contract=off -fno-fast-math -c %s 2>&1 \
70 // RUN:   | FileCheck --check-prefixes=CHECK-FPC-OFF,WARN_FM_OFF %s
71 
72 // RUN: %clang -### -Werror -ffast-math -ffp-contract=fast -fno-fast-math -c %s 2>&1 \
73 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
74 
75 // RUN: %clang -### -Werror -ffast-math -fno-fast-math -c %s 2>&1 \
76 // RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
77 
78 // RUN: %clang -### -Werror -fno-fast-math -ffast-math -c %s 2>&1 \
79 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
80 
81 // RUN: %clang -### -Werror -fno-fast-math -ffp-contract=on -c %s 2>&1 \
82 // RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
83 
84 // RUN: %clang -### -Werror -fno-fast-math -ffp-contract=off -c %s 2>&1 \
85 // RUN:   | FileCheck --check-prefix=CHECK-FPC-OFF %s
86 
87 // RUN: %clang -### -Werror -fno-fast-math -ffp-contract=fast -c %s 2>&1 \
88 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
89 
90 // RUN: %clang -### -Werror -ffp-contract=fast -fno-fast-math -ffp-contract=on \
91 // RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-ON %s
92 
93 // RUN: %clang -### -Werror -ffp-contract=fast -fno-fast-math -ffp-contract=off \
94 // RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-OFF %s
95 
96 // RUN: %clang -### -Werror -ffp-contract=off -fno-fast-math -ffp-contract=fast \
97 // RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-FAST %s
98 
99 // RUN: %clang -### -Werror -ffp-contract=off -fno-fast-math -ffp-contract=on \
100 // RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-ON %s
101 
102 // RUN: %clang -### -Werror -ffp-contract=on -ffast-math -c %s 2>&1 \
103 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
104 
105 // RUN: %clang -### -Werror -ffp-contract=off -ffast-math -c %s 2>&1 \
106 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
107 
108 // RUN: %clang -### -Werror -ffp-contract=fast -ffast-math -c %s 2>&1 \
109 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
110 
111 // RUN: %clang -### -Werror -ffp-contract=on -ffast-math -fno-fast-math -c %s 2>&1 \
112 // RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
113 
114 // RUN: %clang -### -Werror -ffp-contract=off -ffast-math -fno-fast-math -c %s 2>&1 \
115 // RUN:   | FileCheck --check-prefix=CHECK-FPC-OFF %s
116 
117 // RUN: %clang -### -Werror -ffp-contract=fast -ffast-math -fno-fast-math -c %s 2>&1 \
118 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
119 
120 // RUN: %clang -### -Werror -fno-fast-math -ffast-math -ffp-contract=fast \
121 // RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-FAST %s
122 
123 // RUN: %clang -### -fno-fast-math -ffast-math -ffp-contract=on \
124 // RUN: -c %s 2>&1 | FileCheck --check-prefixes=CHECK-FPC-ON,WARN_FM_ON %s
125 
126 // RUN: %clang -### -fno-fast-math -ffast-math -ffp-contract=off \
127 // RUN: -c %s 2>&1 | FileCheck --check-prefixes=CHECK-FPC-OFF,WARN_FM_OFF %s
128 
129 // funsafe-math-optimizations, fno-unsafe-math-optimizations
130 // RUN: %clang -### -Werror -funsafe-math-optimizations -c %s 2>&1  \
131 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
132 
133 // RUN: %clang -### -Werror -fno-unsafe-math-optimizations -c %s 2>&1 \
134 // RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
135 
136 // RUN: %clang -### -funsafe-math-optimizations -ffp-contract=on -c %s 2>&1 \
137 // RUN:   | FileCheck --check-prefixes=CHECK-FPC-ON,WARN_UM_ON %s
138 
139 // RUN: %clang -### -funsafe-math-optimizations -ffp-contract=off -c %s 2>&1 \
140 // RUN:   | FileCheck --check-prefixes=CHECK-FPC-OFF,WARN_UM_OFF %s
141 
142 // RUN: %clang -### -Werror -funsafe-math-optimizations -ffp-contract=fast -c %s 2>&1 \
143 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
144 
145 // RUN: %clang -### -Werror -ffp-contract=fast -funsafe-math-optimizations -c %s 2>&1 \
146 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
147 // RUN: %clang -### -Werror -ffp-contract=on -funsafe-math-optimizations -c %s 2>&1 \
148 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
149 // RUN: %clang -### -Werror -ffp-contract=off -funsafe-math-optimizations -c %s 2>&1 \
150 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
151 
152 // RUN: %clang -### -Werror -ffp-contract=fast -fno-unsafe-math-optimizations -c \
153 // RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-FAST %s
154 // RUN: %clang -### -Werror -ffp-contract=on -fno-unsafe-math-optimizations -c %s 2>&1 \
155 // RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
156 // RUN: %clang -### -Werror -ffp-contract=off -fno-unsafe-math-optimizations -c %s 2>&1 \
157 // RUN:   | FileCheck --check-prefix=CHECK-FPC-OFF %s
158 
159 // RUN: %clang -### -Werror -funsafe-math-optimizations -ffp-contract=fast \
160 // RUN: -ffp-contract=on -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-ON %s
161 
162 // RUN: %clang -### -funsafe-math-optimizations -ffp-contract=on \
163 // RUN: -ffp-contract=off -c %s 2>&1 | FileCheck --check-prefixes=CHECK-FPC-OFF,WARN_UM_ON %s
164 
165 // RUN: %clang -### -funsafe-math-optimizations -ffp-contract=on \
166 // RUN: -ffp-contract=fast -c %s 2>&1 \
167 // RUN:   | FileCheck --check-prefixes=CHECK-FPC-FAST,WARN_UM_ON %s
168 
169 // RUN: %clang -### -funsafe-math-optimizations -ffp-contract=off \
170 // RUN: -ffp-contract=on -c %s 2>&1 | FileCheck --check-prefixes=CHECK-FPC-ON,WARN_UM_OFF %s
171 
172 // RUN: %clang -### -funsafe-math-optimizations -ffp-contract=off \
173 // RUN: -ffp-contract=fast \
174 // RUN: -c %s 2>&1 | FileCheck --check-prefixes=CHECK-FPC-FAST,WARN_UM_OFF %s
175 
176 // RUN: %clang -### -funsafe-math-optimizations -ffp-contract=on \
177 // RUN: -fno-unsafe-math-optimizations -c %s 2>&1 \
178 // RUN:   | FileCheck --check-prefixes=CHECK-FPC-ON,WARN_UM_ON %s
179 
180 // RUN: %clang -### -funsafe-math-optimizations -ffp-contract=off \
181 // RUN: -fno-unsafe-math-optimizations -c %s 2>&1 \
182 // RUN:   | FileCheck --check-prefixes=CHECK-FPC-OFF,WARN_UM_OFF %s
183 
184 // RUN: %clang -### -Werror -funsafe-math-optimizations -ffp-contract=fast \
185 // RUN: -fno-unsafe-math-optimizations -c %s 2>&1 \
186 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
187 
188 // RUN: %clang -### -Werror -funsafe-math-optimizations -fno-unsafe-math-optimizations \
189 // RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-ON %s
190 
191 // RUN: %clang -### -Werror -fno-unsafe-math-optimizations -funsafe-math-optimizations \
192 // RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-FAST %s
193 
194 // RUN: %clang -### -Werror -fno-unsafe-math-optimizations -ffp-contract=on -c %s 2>&1 \
195 // RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
196 
197 // RUN: %clang -### -Werror -fno-unsafe-math-optimizations -ffp-contract=off -c %s 2>&1 \
198 // RUN:   | FileCheck --check-prefix=CHECK-FPC-OFF %s
199 
200 // RUN: %clang -### -Werror -fno-unsafe-math-optimizations -ffp-contract=fast -c %s 2>&1 \
201 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
202 
203 // RUN: %clang -### -Werror -ffp-contract=fast -fno-unsafe-math-optimizations \
204 // RUN: -ffp-contract=on \
205 // RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-ON %s
206 
207 // RUN: %clang -### -Werror -ffp-contract=fast -fno-unsafe-math-optimizations \
208 // RUN: -ffp-contract=off \
209 // RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-OFF %s
210 
211 // RUN: %clang -### -Werror -ffp-contract=off -fno-unsafe-math-optimizations \
212 // RUN: -ffp-contract=fast \
213 // RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-FAST %s
214 
215 // RUN: %clang -### -Werror -ffp-contract=off -fno-unsafe-math-optimizations \
216 // RUN: -ffp-contract=on -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-ON %s
217 
218 // RUN: %clang -### -Werror -ffp-contract=on -funsafe-math-optimizations -c %s 2>&1 \
219 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
220 
221 // RUN: %clang -### -Werror -ffp-contract=off -funsafe-math-optimizations -c %s 2>&1 \
222 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
223 
224 // RUN: %clang -### -Werror -ffp-contract=fast -funsafe-math-optimizations -c %s 2>&1 \
225 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
226 
227 // RUN: %clang -### -Werror -ffp-contract=on -funsafe-math-optimizations -fno-unsafe-math-optimizations -c %s 2>&1 \
228 // RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
229 
230 // RUN: %clang -### -Werror -ffp-contract=off -funsafe-math-optimizations -fno-unsafe-math-optimizations -c %s 2>&1 \
231 // RUN:   | FileCheck --check-prefix=CHECK-FPC-OFF %s
232 
233 // RUN: %clang -### -Werror -ffp-contract=fast -funsafe-math-optimizations -fno-unsafe-math-optimizations -c %s 2>&1 \
234 // RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
235 
236 // RUN: %clang -### -Werror -fno-unsafe-math-optimizations -funsafe-math-optimizations \
237 // RUN:   -ffp-contract=fast \
238 // RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-FAST %s
239 
240 // RUN: %clang -### -fno-unsafe-math-optimizations -funsafe-math-optimizations \
241 // RUN:   -ffp-contract=on -c %s 2>&1 | FileCheck --check-prefixes=CHECK-FPC-ON,WARN_UM_ON %s
242 
243 // RUN: %clang -### -fno-unsafe-math-optimizations -funsafe-math-optimizations \
244 // RUN:   -ffp-contract=off -c %s 2>&1 | FileCheck --check-prefixes=CHECK-FPC-OFF,WARN_UM_OFF %s
245 
246 // RUN: %clang -### -funsafe-math-optimizations -ffp-contract=off -c %s 2>&1 \
247 // RUN:   | FileCheck --check-prefix=WARN_UM_OFF %s
248 
249 // This case should not warn
250 // RUN: %clang -### -Werror -funsafe-math-optimizations \
251 // RUN: -fno-unsafe-math-optimizations -ffp-contract=off -c %s
252 
253 // RUN: %clang -### -ffast-math -ffp-contract=off -c %s 2>&1 \
254 // RUN:   | FileCheck --check-prefix=WARN_FM_OFF %s
255 
256 // This case should not warn
257 // RUN: %clang -### -Werror -ffast-math -fno-fast-math -ffp-contract=off -c %s
258