FP LangOpts should not be dependent on CGOpt

This bug was observed by Apple since their compiler processes LangOpts and CGOpts in a different order.

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D79735
This commit is contained in:
Melanie Blower 2020-05-11 12:29:52 -07:00
parent 5f730b645d
commit 01dc694ccb
1 changed files with 17 additions and 9 deletions

View File

@ -2454,7 +2454,7 @@ static const StringRef GetInputKindName(InputKind IK) {
static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
const TargetOptions &TargetOpts,
PreprocessorOptions &PPOpts, CodeGenOptions &CGOpts,
PreprocessorOptions &PPOpts,
DiagnosticsEngine &Diags) {
// FIXME: Cleanup per-file based stuff.
LangStandard::Kind LangStd = LangStandard::lang_unspecified;
@ -3188,13 +3188,21 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) ||
Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
Args.hasArg(OPT_cl_fast_relaxed_math);
Opts.AllowFPReassoc = Opts.FastMath || CGOpts.Reassociate;
Opts.NoHonorNaNs =
Opts.FastMath || CGOpts.NoNaNsFPMath || Opts.FiniteMathOnly;
Opts.NoHonorInfs =
Opts.FastMath || CGOpts.NoInfsFPMath || Opts.FiniteMathOnly;
Opts.NoSignedZero = Opts.FastMath || CGOpts.NoSignedZeros;
Opts.AllowRecip = Opts.FastMath || CGOpts.ReciprocalMath;
Opts.AllowFPReassoc = Opts.FastMath || Args.hasArg(OPT_mreassociate);
Opts.NoHonorNaNs = Opts.FastMath || Opts.FiniteMathOnly ||
Args.hasArg(OPT_menable_no_nans) ||
Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
Args.hasArg(OPT_cl_finite_math_only) ||
Args.hasArg(OPT_cl_fast_relaxed_math);
Opts.NoHonorInfs = Opts.FastMath || Opts.FiniteMathOnly ||
Args.hasArg(OPT_menable_no_infinities) ||
Args.hasArg(OPT_cl_finite_math_only) ||
Args.hasArg(OPT_cl_fast_relaxed_math);
Opts.NoSignedZero = Opts.FastMath || (Args.hasArg(OPT_fno_signed_zeros) ||
Args.hasArg(OPT_cl_no_signed_zeros) ||
Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
Args.hasArg(OPT_cl_fast_relaxed_math));
Opts.AllowRecip = Opts.FastMath || Args.hasArg(OPT_freciprocal_math);
// Currently there's no clang option to enable this individually
Opts.ApproxFunc = Opts.FastMath;
@ -3652,7 +3660,7 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
// Other LangOpts are only initialized when the input is not AST or LLVM IR.
// FIXME: Should we really be calling this for an Language::Asm input?
ParseLangArgs(LangOpts, Args, DashX, Res.getTargetOpts(),
Res.getPreprocessorOpts(), Res.getCodeGenOpts(), Diags);
Res.getPreprocessorOpts(), Diags);
if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
LangOpts.ObjCExceptions = 1;
if (T.isOSDarwin() && DashX.isPreprocessed()) {