Skip to content

Commit a137c02

Browse files
author
Andy Kaylor
committed
Fix -fno-unsafe-math-optimizations behavior
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 enabled -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 7911615 commit a137c02

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
@@ -1690,7 +1690,6 @@ floating point semantic models: precise (the default), strict, and fast.
16901690
* ``-fno-associative-math``
16911691
* ``-fno-reciprocal-math``
16921692
* ``-fsigned-zeros``
1693-
* ``-ftrapping-math``
16941693
* ``-ffp-contract=on``
16951694
* ``-fdenormal-fp-math=ieee``
16961695

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3151,8 +3151,6 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
31513151
ReciprocalMath = false;
31523152
SignedZeros = true;
31533153
ApproxFunc = false;
3154-
TrappingMath = true;
3155-
FPExceptionBehavior = "strict";
31563154

31573155
// The target may have opted to flush by default, so force IEEE.
31583156
DenormalFPMath = llvm::DenormalMode::getIEEE();

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)