Skip to content

Commit cab9c02

Browse files
committed
[Clang] Fix behavior of -ffp-model option when overriden
-ffp-model=strict -ffp-model=fast will still enable strict exception handling behavior, therefore clang still emits constrained FP operations in IR. -ffp-model=fast -ffp-model=strict emits two warnings: one for strict overriding fast, the other for strict overriding strict, which is confusing. Reviewed By: zahiraam Differential Revision: https://reviews.llvm.org/D137618
1 parent a65d530 commit cab9c02

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,6 +3041,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
30413041
SignedZeros = false;
30423042
TrappingMath = false;
30433043
RoundingFPMath = false;
3044+
FPExceptionBehavior = "";
30443045
// If fast-math is set then set the fp-contract mode to fast.
30453046
FPContract = "fast";
30463047
SeenUnsafeMathModeOption = true;
@@ -3081,10 +3082,12 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
30813082
else {
30823083
StrictFPModel = false;
30833084
FPModel = "";
3084-
D.Diag(clang::diag::warn_drv_overriding_flag_option)
3085-
<< "-ffp-model=strict" <<
3086-
((A->getNumValues() == 0) ? A->getSpelling()
3087-
: Args.MakeArgString(A->getSpelling() + A->getValue()));
3085+
auto RHS = (A->getNumValues() == 0)
3086+
? A->getSpelling()
3087+
: Args.MakeArgString(A->getSpelling() + A->getValue());
3088+
if (RHS != "-ffp-model=strict")
3089+
D.Diag(clang::diag::warn_drv_overriding_flag_option)
3090+
<< "-ffp-model=strict" << RHS;
30883091
}
30893092
}
30903093

clang/test/CodeGen/ffp-model.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ float mymuladd(float x, float y, float z) {
3636

3737
// CHECK-STRICT-FAST: load float, ptr
3838
// CHECK-STRICT-FAST: load float, ptr
39-
// CHECK-STRICT-FAST: call fast float @llvm.experimental.constrained.fmul.f32(float {{.*}}, float {{.*}}, {{.*}})
39+
// CHECK-STRICT-FAST: fmul fast float {{.*}}, {{.*}}
4040
// CHECK-STRICT-FAST: load float, ptr
41-
// CHECK-STRICT-FAST: call fast float @llvm.experimental.constrained.fadd.f32(float {{.*}}, float {{.*}}, {{.*}}
41+
// CHECK-STRICT-FAST: fadd fast float {{.*}}, {{.*}}
4242

4343
// CHECK-FAST1: load float, ptr
4444
// CHECK-FAST1: load float, ptr

clang/test/Driver/fp-model.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@
6666
// RUN: | FileCheck --check-prefix=WARN10 %s
6767
// WARN10: warning: overriding '-ffp-model=strict' option with '-fdenormal-fp-math=preserve-sign,preserve-sign' [-Woverriding-t-option]
6868

69+
// RUN: %clang -### -ffp-model=fast -ffp-model=strict -c %s 2>&1 | FileCheck \
70+
// RUN: --check-prefix=WARN11 %s
71+
// WARN11: warning: overriding '-ffp-model=fast' option with '-ffp-model=strict' [-Woverriding-t-option]
72+
// WARN11-NOT: warning: overriding '-ffp-model=strict' option with '-ffp-model=strict' [-Woverriding-t-option]
73+
74+
// RUN: %clang -### -Ofast -ffp-model=strict -c %s 2>&1 | FileCheck \
75+
// RUN: --check-prefix=WARN12 %s
76+
// RUN: %clang -### -ffast-math -ffp-model=strict -c %s 2>&1 | FileCheck \
77+
// RUN: --check-prefix=WARN12 %s
78+
// WARN12-NOT: warning: overriding '-ffp-model=strict' option with '-ffp-model=strict' [-Woverriding-t-option]
79+
6980
// RUN: %clang -### -c %s 2>&1 \
7081
// RUN: | FileCheck --check-prefix=CHECK-NOROUND %s
7182
// CHECK-NOROUND: "-cc1"
@@ -107,6 +118,13 @@
107118
// CHECK-FPM-STRICT: "-frounding-math"
108119
// CHECK-FPM-STRICT: "-ffp-exception-behavior=strict"
109120

121+
// RUN: %clang -### -nostdinc -ffp-model=strict -ffp-model=fast -c %s 2>&1 \
122+
// RUN: | FileCheck --check-prefix=CHECK-NO-EXCEPT %s
123+
// RUN: %clang -### -nostdinc -ffp-model=strict -ffast-math -c %s 2>&1 \
124+
// RUN: | FileCheck --check-prefix=CHECK-NO-EXCEPT %s
125+
// RUN: %clang -### -nostdinc -ffp-model=strict -Ofast -c %s 2>&1 \
126+
// RUN: | FileCheck --check-prefix=CHECK-NO-EXCEPT %s
127+
// CHECK-NO-EXCEPT-NOT: "-ffp-exception-behavior=strict"
110128

111129
// RUN: %clang -### -nostdinc -ffp-exception-behavior=strict -c %s 2>&1 \
112130
// RUN: | FileCheck --check-prefix=CHECK-FEB-STRICT %s

0 commit comments

Comments
 (0)