Skip to content

Commit 01dc694

Browse files
author
Melanie Blower
committed
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
1 parent 5f730b6 commit 01dc694

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,7 +2454,7 @@ static const StringRef GetInputKindName(InputKind IK) {
24542454

24552455
static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
24562456
const TargetOptions &TargetOpts,
2457-
PreprocessorOptions &PPOpts, CodeGenOptions &CGOpts,
2457+
PreprocessorOptions &PPOpts,
24582458
DiagnosticsEngine &Diags) {
24592459
// FIXME: Cleanup per-file based stuff.
24602460
LangStandard::Kind LangStd = LangStandard::lang_unspecified;
@@ -3188,13 +3188,21 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
31883188
Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) ||
31893189
Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
31903190
Args.hasArg(OPT_cl_fast_relaxed_math);
3191-
Opts.AllowFPReassoc = Opts.FastMath || CGOpts.Reassociate;
3192-
Opts.NoHonorNaNs =
3193-
Opts.FastMath || CGOpts.NoNaNsFPMath || Opts.FiniteMathOnly;
3194-
Opts.NoHonorInfs =
3195-
Opts.FastMath || CGOpts.NoInfsFPMath || Opts.FiniteMathOnly;
3196-
Opts.NoSignedZero = Opts.FastMath || CGOpts.NoSignedZeros;
3197-
Opts.AllowRecip = Opts.FastMath || CGOpts.ReciprocalMath;
3191+
Opts.AllowFPReassoc = Opts.FastMath || Args.hasArg(OPT_mreassociate);
3192+
Opts.NoHonorNaNs = Opts.FastMath || Opts.FiniteMathOnly ||
3193+
Args.hasArg(OPT_menable_no_nans) ||
3194+
Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
3195+
Args.hasArg(OPT_cl_finite_math_only) ||
3196+
Args.hasArg(OPT_cl_fast_relaxed_math);
3197+
Opts.NoHonorInfs = Opts.FastMath || Opts.FiniteMathOnly ||
3198+
Args.hasArg(OPT_menable_no_infinities) ||
3199+
Args.hasArg(OPT_cl_finite_math_only) ||
3200+
Args.hasArg(OPT_cl_fast_relaxed_math);
3201+
Opts.NoSignedZero = Opts.FastMath || (Args.hasArg(OPT_fno_signed_zeros) ||
3202+
Args.hasArg(OPT_cl_no_signed_zeros) ||
3203+
Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
3204+
Args.hasArg(OPT_cl_fast_relaxed_math));
3205+
Opts.AllowRecip = Opts.FastMath || Args.hasArg(OPT_freciprocal_math);
31983206
// Currently there's no clang option to enable this individually
31993207
Opts.ApproxFunc = Opts.FastMath;
32003208

@@ -3652,7 +3660,7 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
36523660
// Other LangOpts are only initialized when the input is not AST or LLVM IR.
36533661
// FIXME: Should we really be calling this for an Language::Asm input?
36543662
ParseLangArgs(LangOpts, Args, DashX, Res.getTargetOpts(),
3655-
Res.getPreprocessorOpts(), Res.getCodeGenOpts(), Diags);
3663+
Res.getPreprocessorOpts(), Diags);
36563664
if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
36573665
LangOpts.ObjCExceptions = 1;
36583666
if (T.isOSDarwin() && DashX.isPreprocessed()) {

0 commit comments

Comments
 (0)