diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 942ebbc410607..4459d86e77d5d 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2778,6 +2778,26 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, LangOptions::ComplexRangeKind Range = LangOptions::ComplexRangeKind::CX_None; std::string ComplexRangeStr = ""; + // Lambda to set fast-math options. This is also used by -ffp-model=fast + auto applyFastMath = [&]() { + HonorINFs = false; + HonorNaNs = false; + MathErrno = false; + AssociativeMath = true; + ReciprocalMath = true; + ApproxFunc = true; + SignedZeros = false; + TrappingMath = false; + RoundingFPMath = false; + FPExceptionBehavior = ""; + // If fast-math is set then set the fp-contract mode to fast. + FPContract = "fast"; + // ffast-math enables limited range rules for complex multiplication and + // division. + Range = LangOptions::ComplexRangeKind::CX_Limited; + SeenUnsafeMathModeOption = true; + }; + if (const Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) { CmdArgs.push_back("-mlimit-float-precision"); CmdArgs.push_back(A->getValue()); @@ -2842,9 +2862,8 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, << Args.MakeArgString("-ffp-model=" + FPModel) << Args.MakeArgString("-ffp-model=" + Val); if (Val.equals("fast")) { - optID = options::OPT_ffast_math; FPModel = Val; - FPContract = "fast"; + applyFastMath(); } else if (Val.equals("precise")) { optID = options::OPT_ffp_contract; FPModel = Val; @@ -3061,22 +3080,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, continue; [[fallthrough]]; case options::OPT_ffast_math: { - HonorINFs = false; - HonorNaNs = false; - MathErrno = false; - AssociativeMath = true; - ReciprocalMath = true; - ApproxFunc = true; - SignedZeros = false; - TrappingMath = false; - RoundingFPMath = false; - FPExceptionBehavior = ""; - // If fast-math is set then set the fp-contract mode to fast. - FPContract = "fast"; - SeenUnsafeMathModeOption = true; - // ffast-math enables fortran rules for complex multiplication and - // division. - Range = LangOptions::ComplexRangeKind::CX_Limited; + applyFastMath(); break; } case options::OPT_fno_fast_math: