Skip to content

Commit fb85a28

Browse files
author
Andy Kaylor
authored
Fix -fno-unsafe-math-optimizations behavior (#89473)
This changes the handling of -fno-unsafe-fp-math to stop having that option imply -ftrapping-math. In gcc, -fno-unsafe-math-optimizations sets -ftrapping-math, but that dependency is based on the fact the -ftrapping-math is enabled by default in gcc. Because clang does not enable -ftrapping-math by default, there is no reason for -fno-unsafe-math-optimizations to set it. On the other hand, -funsafe-math-optimizations continues to imply -fno-trapping-math because this option necessarily disables strict exception semantics. This fixes #87523
1 parent 51aac5b commit fb85a28

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

clang/docs/UsersManual.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,6 @@ for more details.
16961696
* ``-fno-associative-math``
16971697
* ``-fno-reciprocal-math``
16981698
* ``-fsigned-zeros``
1699-
* ``-ftrapping-math``
17001699
* ``-ffp-contract=on``
17011700

17021701
There is ambiguity about how ``-ffp-contract``,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3112,8 +3112,6 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
31123112
ReciprocalMath = false;
31133113
SignedZeros = true;
31143114
ApproxFunc = false;
3115-
TrappingMath = true;
3116-
FPExceptionBehavior = "strict";
31173115

31183116
if (!JA.isDeviceOffloading(Action::OFK_Cuda) &&
31193117
!JA.isOffloading(Action::OFK_HIP)) {

clang/test/Driver/fast-math.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157

158158
// FIXME: This case leaves nnan and ninf. That seems wrong!
159159
// RUN: %clang -### -ffast-math -fno-unsafe-math-optimizations -c %s 2>&1 \
160-
// RUN: | FileCheck --check-prefixes=CHECK,NO-FAST,NINF,NNAN,FINITE-ONLY,NO-REASSOC,NO-NSZ,NO-ARCP,NO-AFN,NOROUNDING %s
160+
// RUN: | FileCheck --check-prefixes=CHECK,NO-FAST,NINF,NNAN,FINITE-ONLY,NO-REASSOC,NO-NSZ,NO-ARCP,NO-AFN,NOROUNDING,NO-TRAPPING %s
161161
// RUN: %clang -### -ffast-math -fmath-errno -c %s 2>&1 \
162162
// RUN: | FileCheck --check-prefixes=CHECK,NO-FAST,NINF,NNAN,FINITE-ONLY,REASSOC,NSZ,ARCP,AFN,CONTRACT-FAST,ERRNO,NOROUNDING %s
163163
// RUN: %clang -### -ffast-math -fno-associative-math -c %s 2>&1 \
@@ -209,7 +209,7 @@
209209

210210
// RUN: %clang -### -funsafe-math-optimizations -fno-unsafe-math-optimizations \
211211
// RUN: -c %s 2>&1 \
212-
// RUN: | FileCheck --check-prefixes=CHECK,NO-UNSAFE,NO-REASSOC,NO-ARCP,NO-NSZ,NO-AFN %s
212+
// RUN: | FileCheck --check-prefixes=CHECK,NO-UNSAFE,NO-REASSOC,NO-ARCP,NO-NSZ,NO-AFN,NO-TRAPPING %s
213213
// RUN: %clang -### -ffast-math -fno-associative-math -c %s 2>&1 \
214214
// RUN: | FileCheck --check-prefixes=CHECK,NO-UNSAFE,NO-REASSOC,ARCP,NSZ,AFN %s
215215

@@ -224,9 +224,8 @@
224224
// RUN: %clang -### -ffast-math -ftrapping-math -c %s 2>&1 \
225225
// RUN: | FileCheck --check-prefixes=CHECK,NO-FAST,NO-UNSAFE,ARCP,NSZ,AFN,TRAPPING %s
226226

227-
// FIXME: -fno-unsafe-math-optimizations shouldn't imply trapping math
228227
// RUN: %clang -### -ffast-math -fno-unsafe-math-optimizations -c %s 2>&1 \
229-
// RUN: | FileCheck --check-prefixes=CHECK,NO-FAST,NO-UNSAFE,NO-ARCP,NO-NSZ,NO-AFN,TRAPPING %s
228+
// RUN: | FileCheck --check-prefixes=CHECK,NO-FAST,NO-UNSAFE,NO-ARCP,NO-NSZ,NO-AFN,NO-TRAPPING %s
230229

231230
// Reassociate is allowed because it does not require reciprocal-math.
232231

0 commit comments

Comments
 (0)