diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2873,6 +2873,7 @@ AssociativeMath = true; ReciprocalMath = true; SignedZeros = false; + ApproxFunc = true; TrappingMath = false; FPExceptionBehavior = ""; break; @@ -2880,6 +2881,7 @@ AssociativeMath = false; ReciprocalMath = false; SignedZeros = true; + ApproxFunc = false; TrappingMath = true; FPExceptionBehavior = "strict"; @@ -2899,6 +2901,7 @@ MathErrno = false; AssociativeMath = true; ReciprocalMath = true; + ApproxFunc = true; SignedZeros = false; TrappingMath = false; RoundingFPMath = false; @@ -2914,6 +2917,7 @@ MathErrno = TC.IsMathErrnoDefault(); AssociativeMath = false; ReciprocalMath = false; + ApproxFunc = false; SignedZeros = true; // -fno_fast_math restores default denormal and fpcontract handling DenormalFPMath = DefaultDenormalFPMath; @@ -2932,7 +2936,7 @@ // If -ffp-model=strict has been specified on command line but // subsequent options conflict then emit warning diagnostic. if (HonorINFs && HonorNaNs && !AssociativeMath && !ReciprocalMath && - SignedZeros && TrappingMath && RoundingFPMath && + SignedZeros && TrappingMath && RoundingFPMath && !ApproxFunc && DenormalFPMath == llvm::DenormalMode::getIEEE() && DenormalFP32Math == llvm::DenormalMode::getIEEE() && FPContract.equals("off")) @@ -2965,7 +2969,7 @@ CmdArgs.push_back("-fmath-errno"); if (!MathErrno && AssociativeMath && ReciprocalMath && !SignedZeros && - !TrappingMath) + ApproxFunc && !TrappingMath) CmdArgs.push_back("-menable-unsafe-fp-math"); if (!SignedZeros) @@ -3016,7 +3020,7 @@ // -ffast-math enables the __FAST_MATH__ preprocessor macro, but check for the // individual features enabled by -ffast-math instead of the option itself as // that's consistent with gcc's behaviour. - if (!HonorINFs && !HonorNaNs && !MathErrno && AssociativeMath && + if (!HonorINFs && !HonorNaNs && !MathErrno && AssociativeMath && ApproxFunc && ReciprocalMath && !SignedZeros && !TrappingMath && !RoundingFPMath) { CmdArgs.push_back("-ffast-math"); if (FPModel.equals("fast")) { diff --git a/clang/test/Driver/fast-math.c b/clang/test/Driver/fast-math.c --- a/clang/test/Driver/fast-math.c +++ b/clang/test/Driver/fast-math.c @@ -70,6 +70,23 @@ // CHECK-NO-NANS-NO-FAST-MATH: "-cc1" // CHECK-NO-NANS-NO-FAST-MATH-NOT: "-menable-no-nans" // +// RUN: %clang -### -ffast-math -fno-approx-func -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FAST-MATH-NO-APPROX-FUNC %s +// CHECK-FAST-MATH-NO-APPROX-FUNC: "-cc1" +// CHECK-FAST-MATH-NO-APPROX-FUNC: "-menable-no-infs" +// CHECK-FAST-MATH-NO-APPROX-FUNC: "-menable-no-nans" +// CHECK-FAST-MATH-NO-APPROX-FUNC: "-fno-signed-zeros" +// CHECK-FAST-MATH-NO-APPROX-FUNC: "-mreassociate" +// CHECK-FAST-MATH-NO-APPROX-FUNC: "-freciprocal-math" +// CHECK-FAST-MATH-NO-APPROX-FUNC: "-ffp-contract=fast" +// CHECK-FAST-MATH-NO-APPROX-FUNC-NOT: "-ffast-math" +// CHECK-FAST-MATH-NO-APPROX-FUNC-NOT: "-fapprox-func" +// +// RUN: %clang -### -fno-approx-func -ffast-math -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-APPROX-FUNC-FAST-MATH %s +// CHECK-NO-APPROX-FUNC-FAST-MATH: "-cc1" +// CHECK-NO-APPROX-FUNC-FAST-MATH: "-ffast-math" +// // RUN: %clang -### -fapprox-func -c %s 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-APPROX-FUNC %s // CHECK-APPROX-FUNC: "-cc1" @@ -130,14 +147,14 @@ // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s // // RUN: %clang -### -fno-math-errno -fassociative-math -freciprocal-math \ -// RUN: -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \ +// RUN: -fno-signed-zeros -fno-trapping-math -fapprox-func -c %s 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s // CHECK-UNSAFE-MATH: "-cc1" // CHECK-UNSAFE-MATH: "-menable-unsafe-fp-math" // CHECK-UNSAFE-MATH: "-mreassociate" // // RUN: %clang -### -fno-fast-math -fno-math-errno -fassociative-math -freciprocal-math \ -// RUN: -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \ +// RUN: -fno-signed-zeros -fno-trapping-math -fapprox-func -c %s 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH-UNSAFE-MATH %s // CHECK-NO-FAST-MATH-UNSAFE-MATH: "-cc1" // CHECK-NO-FAST-MATH-UNSAFE-MATH: "-menable-unsafe-fp-math" @@ -178,7 +195,7 @@ // RUN: -fno-math-errno -ffp-contract=fast -fno-rounding-math -c %s 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-FAST-MATH %s // RUN: %clang -### -fno-honor-infinities -fno-honor-nans -fno-math-errno \ -// RUN: -fassociative-math -freciprocal-math -fno-signed-zeros \ +// RUN: -fassociative-math -freciprocal-math -fno-signed-zeros -fapprox-func \ // RUN: -fno-trapping-math -ffp-contract=fast -fno-rounding-math -c %s 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-FAST-MATH %s // CHECK-FAST-MATH: "-cc1" diff --git a/clang/test/Preprocessor/aarch64-target-features.c b/clang/test/Preprocessor/aarch64-target-features.c --- a/clang/test/Preprocessor/aarch64-target-features.c +++ b/clang/test/Preprocessor/aarch64-target-features.c @@ -115,7 +115,7 @@ // CHECK-CRC32: __ARM_FEATURE_CRC32 1 // RUN: %clang -target aarch64-none-linux-gnu -fno-math-errno -fno-signed-zeros\ -// RUN: -fno-trapping-math -fassociative-math -freciprocal-math\ +// RUN: -fno-trapping-math -fassociative-math -freciprocal-math -fapprox-func\ // RUN: -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FASTMATH %s // RUN: %clang -target aarch64-none-linux-gnu -ffast-math -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FASTMATH %s // RUN: %clang -target arm64-none-linux-gnu -ffast-math -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FASTMATH %s diff --git a/clang/test/Preprocessor/arm-target-features.c b/clang/test/Preprocessor/arm-target-features.c --- a/clang/test/Preprocessor/arm-target-features.c +++ b/clang/test/Preprocessor/arm-target-features.c @@ -267,7 +267,7 @@ // CHECK-DEFS:#define __ARM_SIZEOF_WCHAR_T 4 // RUN: %clang -target arm-none-linux-gnu -fno-math-errno -fno-signed-zeros\ -// RUN: -fno-trapping-math -fassociative-math -freciprocal-math\ +// RUN: -fno-trapping-math -fassociative-math -freciprocal-math -fapprox-func\ // RUN: -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FASTMATH %s // RUN: %clang -target arm-none-linux-gnu -ffast-math -x c -E -dM %s -o -\ // RUN: | FileCheck -match-full-lines --check-prefix=CHECK-FASTMATH %s