Skip to content

Commit cec7c2b

Browse files
committed
Revert "[CLANG][PATCH][FPEnv] Add support for option -ffp-eval-method and extend #pragma float_control similarly"
The intent of this patch is to add support of -fp-model=[source|double|extended] to allow the compiler to use a wider type for intermediate floating point calculations. As a side effect to that, the value of FLT_EVAL_METHOD is changed according to the pragma float_control. Unfortunately some issue was uncovered with this change in preprocessing. See details in https://reviews.llvm.org/D93769 . We are therefore reverting this patch until we find a way to reconcile the value of FLT_EVAL_METHOD, the pragma and the -E flow. This reverts commit 66ddac2.
1 parent f024a48 commit cec7c2b

31 files changed

+88
-303
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3579,7 +3579,7 @@ specification, a stack is supported so that the ``pragma float_control``
35793579
settings can be pushed or popped.
35803580
35813581
When ``pragma float_control(precise, on)`` is enabled, the section of code
3582-
governed by the pragma uses precise floating-point semantics, effectively
3582+
governed by the pragma uses precise floating point semantics, effectively
35833583
``-ffast-math`` is disabled and ``-ffp-contract=on``
35843584
(fused multiply add) is enabled.
35853585
@@ -3590,29 +3590,8 @@ when ``pragma float_control(precise, off)`` is enabled, the section of code
35903590
governed by the pragma behaves as though the command-line option
35913591
``-ffp-exception-behavior=ignore`` is enabled.
35923592
3593-
When ``pragma float_control(source, on)`` is enabled, the section of code governed
3594-
by the pragma behaves as though the command-line option
3595-
``-ffp-eval-method=source`` is enabled. Note: The default
3596-
floating-point evaluation method is target-specific, typically ``source``.
3597-
3598-
When ``pragma float_control(double, on)`` is enabled, the section of code governed
3599-
by the pragma behaves as though the command-line option
3600-
``-ffp-eval-method=double`` is enabled.
3601-
3602-
When ``pragma float_control(extended, on)`` is enabled, the section of code governed
3603-
by the pragma behaves as though the command-line option
3604-
``-ffp-eval-method=extended`` is enabled.
3605-
3606-
When ``pragma float_control(source, off)`` or
3607-
``pragma float_control(double, off)`` or
3608-
``pragma float_control(extended, off)`` is enabled,
3609-
the section of code governed
3610-
by the pragma behaves as though the command-line option
3611-
``-ffp-eval-method=source`` is enabled, returning floating-point evaluation
3612-
method to the default setting.
3613-
36143593
The full syntax this pragma supports is
3615-
``float_control(except|precise|source|double|extended, on|off [, push])`` and
3594+
``float_control(except|precise, on|off [, push])`` and
36163595
``float_control(push|pop)``.
36173596
The ``push`` and ``pop`` forms, including using ``push`` as the optional
36183597
third argument, can only occur at file scope.

clang/docs/UsersManual.rst

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,17 +1478,6 @@ Note that floating-point operations performed as part of constant initialization
14781478
* ``maytrap`` The compiler avoids transformations that may raise exceptions that would not have been raised by the original code. Constant folding performed by the compiler is exempt from this option.
14791479
* ``strict`` The compiler ensures that all transformations strictly preserve the floating point exception semantics of the original code.
14801480

1481-
.. option:: -ffp-eval-method=<value>
1482-
1483-
Specify the floating-point evaluation method.
1484-
1485-
Valid values are: ``source``, ``double``, and ``extended``.
1486-
The default value is target-specific, typically ``source``. Details:
1487-
1488-
* ``source`` The compiler uses the floating-point type declared in the source program as the evaluation method.
1489-
* ``double`` The compiler uses ``double`` as the floating-point evaluation method for all float expressions of type that is narrower than ``double``.
1490-
* ``extended`` The compiler uses ``long double`` as the floating-point evaluation method for all float expressions of type that is narrower than ``long double``.
1491-
14921481
.. option:: -f[no-]protect-parens:
14931482

14941483
This option pertains to floating-point types, complex types with

clang/include/clang/Basic/FPOptions.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ OPTION(NoHonorInfs, bool, 1, NoHonorNaNs)
2323
OPTION(NoSignedZero, bool, 1, NoHonorInfs)
2424
OPTION(AllowReciprocal, bool, 1, NoSignedZero)
2525
OPTION(AllowApproxFunc, bool, 1, AllowReciprocal)
26-
OPTION(FPEvalMethod, LangOptions::FPEvalMethodKind, 2, AllowApproxFunc)
2726
#undef OPTION

clang/include/clang/Basic/LangOptions.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ BENIGN_ENUM_LANGOPT(DefaultFPContractMode, FPModeKind, 2, FPM_Off, "FP contracti
298298
COMPATIBLE_LANGOPT(ExpStrictFP, 1, false, "Enable experimental strict floating point")
299299
BENIGN_ENUM_LANGOPT(FPRoundingMode, RoundingMode, 3, RoundingMode::NearestTiesToEven, "FP Rounding Mode type")
300300
BENIGN_ENUM_LANGOPT(FPExceptionMode, FPExceptionModeKind, 2, FPE_Ignore, "FP Exception Behavior Mode type")
301-
BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 2, FEM_TargetDefault, "FP type used for floating point arithmetic")
302301
LANGOPT(NoBitFieldTypeAlign , 1, 0, "bit-field type alignment")
303302
LANGOPT(HexagonQdsp6Compat , 1, 0, "hexagon-qdsp6 backward compatibility")
304303
LANGOPT(ObjCAutoRefCount , 1, 0, "Objective-C automated reference counting")

clang/include/clang/Basic/LangOptions.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,19 +233,6 @@ class LangOptions : public LangOptionsBase {
233233
/// Possible exception handling behavior.
234234
enum class ExceptionHandlingKind { None, SjLj, WinEH, DwarfCFI, Wasm };
235235

236-
/// Possible float expression evaluation method choices.
237-
enum FPEvalMethodKind {
238-
/// Use the declared type for fp arithmetic.
239-
FEM_Source,
240-
/// Use the type double for fp arithmetic.
241-
FEM_Double,
242-
/// Use extended type for fp arithmetic.
243-
FEM_Extended,
244-
/// Use the default float eval method specified by Target:
245-
// most targets are defined with evaluation method FEM_Source.
246-
FEM_TargetDefault
247-
};
248-
249236
enum class LaxVectorConversionKind {
250237
/// Permit no implicit vector bitcasts.
251238
None,
@@ -550,7 +537,6 @@ class FPOptions {
550537
setAllowFEnvAccess(true);
551538
else
552539
setAllowFEnvAccess(LangOptions::FPM_Off);
553-
setFPEvalMethod(LO.getFPEvalMethod());
554540
}
555541

556542
bool allowFPContractWithinStatement() const {

clang/include/clang/Basic/PragmaKinds.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ enum PragmaFloatControlKind {
3232
PFC_Except, // #pragma float_control(except [,on])
3333
PFC_NoExcept, // #pragma float_control(except, off)
3434
PFC_Push, // #pragma float_control(push)
35-
PFC_Pop, // #pragma float_control(pop)
36-
PFC_Source, // #pragma float_control(source, {on|off} [,push])
37-
PFC_Double, // #pragma float_control(double, {on|off} [,push])
38-
PFC_Extended, // #pragma float_control(extended, {on|off} [,push])
35+
PFC_Pop // #pragma float_control(pop)
3936
};
4037
}
4138

clang/include/clang/Basic/TargetInfo.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
684684
}
685685

686686
/// Return the value for the C99 FLT_EVAL_METHOD macro.
687-
// Note: implementation defined values may be negative.
688-
virtual int getFPEvalMethod() const { return 0; }
687+
virtual unsigned getFloatEvalMethod() const { return 0; }
689688

690689
// getLargeArrayMinWidth/Align - Return the minimum array size that is
691690
// 'large' and its alignment.

clang/include/clang/Driver/Options.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,11 +1463,6 @@ def : Flag<["-"], "fextended-identifiers">, Group<clang_ignored_f_Group>;
14631463
def : Flag<["-"], "fno-extended-identifiers">, Group<f_Group>, Flags<[Unsupported]>;
14641464
def fhosted : Flag<["-"], "fhosted">, Group<f_Group>;
14651465
def fdenormal_fp_math_EQ : Joined<["-"], "fdenormal-fp-math=">, Group<f_Group>, Flags<[CC1Option]>;
1466-
def ffp_eval_method_EQ : Joined<["-"], "ffp-eval-method=">, Group<f_Group>, Flags<[CC1Option]>,
1467-
HelpText<"Specifies the evaluation method to use for floating-point arithmetic.">,
1468-
Values<"source,double,extended">, NormalizedValuesScope<"LangOptions">,
1469-
NormalizedValues<["FEM_Source", "FEM_Double", "FEM_Extended"]>,
1470-
MarshallingInfoEnum<LangOpts<"FPEvalMethod">, "FEM_TargetDefault">;
14711466
def ffp_model_EQ : Joined<["-"], "ffp-model=">, Group<f_Group>, Flags<[NoXarchOption]>,
14721467
HelpText<"Controls the semantics of floating-point calculations.">;
14731468
def ffp_exception_behavior_EQ : Joined<["-"], "ffp-exception-behavior=">, Group<f_Group>, Flags<[CC1Option]>,

clang/include/clang/Lex/Preprocessor.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,12 @@ class Preprocessor {
179179
IdentifierInfo *Ident__is_target_vendor; // __is_target_vendor
180180
IdentifierInfo *Ident__is_target_os; // __is_target_os
181181
IdentifierInfo *Ident__is_target_environment; // __is_target_environment
182-
IdentifierInfo *Ident__FLT_EVAL_METHOD__ = nullptr; // __FLT_EVAL_METHOD__
183182

184183
// Weak, only valid (and set) while InMacroArgs is true.
185184
Token* ArgMacro;
186185

187186
SourceLocation DATELoc, TIMELoc;
188187

189-
// Corresponding to __FLT_EVAL_METHOD__. Initialized from TargetInfo
190-
// or the command line. Implementation-defined values can be negative.
191-
int CurrentFPEvalMethod = 0;
192-
193188
// Next __COUNTER__ value, starts at 0.
194189
unsigned CounterValue = 0;
195190

@@ -2008,8 +2003,6 @@ class Preprocessor {
20082003
}
20092004
unsigned getCounterValue() const { return CounterValue; }
20102005
void setCounterValue(unsigned V) { CounterValue = V; }
2011-
int getCurrentFPEvalMethod() const { return CurrentFPEvalMethod; }
2012-
void setCurrentFPEvalMethod(int V) { CurrentFPEvalMethod = V; }
20132006

20142007
/// Retrieves the module that we're currently building, if any.
20152008
Module *getCurrentModule();

clang/include/clang/Lex/PreprocessorOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ class PreprocessorOptions {
146146
/// When enabled, the preprocessor will construct editor placeholder tokens.
147147
bool LexEditorPlaceholders = true;
148148

149-
/// When enabled, the preprocessor will expand special builtin macros.
150-
bool LexExpandSpecialBuiltins = true;
151-
152149
/// True if the SourceManager should report the original file name for
153150
/// contents of files that were remapped to other files. Defaults to true.
154151
bool RemappedFilesKeepOriginalName = true;
@@ -249,7 +246,6 @@ class PreprocessorOptions {
249246
ImplicitPCHInclude.clear();
250247
SingleFileParseMode = false;
251248
LexEditorPlaceholders = true;
252-
LexExpandSpecialBuiltins = true;
253249
RetainRemappedFileBuffers = true;
254250
PrecompiledPreambleBytes.first = 0;
255251
PrecompiledPreambleBytes.second = false;

clang/include/clang/Sema/Sema.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,15 +1502,19 @@ class Sema final {
15021502
/// statements.
15031503
class FPFeaturesStateRAII {
15041504
public:
1505-
FPFeaturesStateRAII(Sema &S);
1506-
~FPFeaturesStateRAII();
1505+
FPFeaturesStateRAII(Sema &S) : S(S), OldFPFeaturesState(S.CurFPFeatures) {
1506+
OldOverrides = S.FpPragmaStack.CurrentValue;
1507+
}
1508+
~FPFeaturesStateRAII() {
1509+
S.CurFPFeatures = OldFPFeaturesState;
1510+
S.FpPragmaStack.CurrentValue = OldOverrides;
1511+
}
15071512
FPOptionsOverride getOverrides() { return OldOverrides; }
15081513

15091514
private:
15101515
Sema& S;
15111516
FPOptions OldFPFeaturesState;
15121517
FPOptionsOverride OldOverrides;
1513-
int OldEvalMethod;
15141518
};
15151519

15161520
void addImplicitTypedef(StringRef Name, QualType T);

clang/lib/Basic/Targets/OSTargets.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ class AIXTargetInfo : public OSTargetInfo<Target> {
737737
}
738738

739739
// AIX sets FLT_EVAL_METHOD to be 1.
740-
int getFPEvalMethod() const override { return 1; }
740+
unsigned getFloatEvalMethod() const override { return 1; }
741741
bool hasInt128Type() const override { return false; }
742742

743743
bool defaultsToAIXPowerAlignment() const override { return true; }

clang/lib/Basic/Targets/X86.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo {
166166
return LongDoubleFormat == &llvm::APFloat::IEEEquad() ? "g" : "e";
167167
}
168168

169-
int getFPEvalMethod() const override {
169+
unsigned getFloatEvalMethod() const override {
170170
// X87 evaluates with 80 bits "long double" precision.
171171
return SSELevel == NoSSE ? 2 : 0;
172172
}
@@ -469,12 +469,12 @@ class LLVM_LIBRARY_VISIBILITY NetBSDI386TargetInfo
469469
NetBSDI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
470470
: NetBSDTargetInfo<X86_32TargetInfo>(Triple, Opts) {}
471471

472-
int getFPEvalMethod() const override {
472+
unsigned getFloatEvalMethod() const override {
473473
unsigned Major, Minor, Micro;
474474
getTriple().getOSVersion(Major, Minor, Micro);
475475
// New NetBSD uses the default rounding mode.
476476
if (Major >= 7 || (Major == 6 && Minor == 99 && Micro >= 26) || Major == 0)
477-
return X86_32TargetInfo::getFPEvalMethod();
477+
return X86_32TargetInfo::getFloatEvalMethod();
478478
// NetBSD before 6.99.26 defaults to "double" rounding.
479479
return 1;
480480
}

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,8 +2632,6 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
26322632
StringRef FPModel = "";
26332633
// -ffp-exception-behavior options: strict, maytrap, ignore
26342634
StringRef FPExceptionBehavior = "";
2635-
// -ffp-eval-method options: double, extended, source
2636-
StringRef FPEvalMethod = "";
26372635
const llvm::DenormalMode DefaultDenormalFPMath =
26382636
TC.getDefaultDenormalModeForType(Args, JA);
26392637
const llvm::DenormalMode DefaultDenormalFP32Math =
@@ -2825,18 +2823,6 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
28252823
break;
28262824
}
28272825

2828-
// Validate and pass through -ffp-eval-method option.
2829-
case options::OPT_ffp_eval_method_EQ: {
2830-
StringRef Val = A->getValue();
2831-
if (Val.equals("double") || Val.equals("extended") ||
2832-
Val.equals("source"))
2833-
FPEvalMethod = Val;
2834-
else
2835-
D.Diag(diag::err_drv_unsupported_option_argument)
2836-
<< A->getOption().getName() << Val;
2837-
break;
2838-
}
2839-
28402826
case options::OPT_ffinite_math_only:
28412827
HonorINFs = false;
28422828
HonorNaNs = false;
@@ -2981,9 +2967,6 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
29812967
CmdArgs.push_back(Args.MakeArgString("-ffp-exception-behavior=" +
29822968
FPExceptionBehavior));
29832969

2984-
if (!FPEvalMethod.empty())
2985-
CmdArgs.push_back(Args.MakeArgString("-ffp-eval-method=" + FPEvalMethod));
2986-
29872970
ParseMRecip(D, Args, CmdArgs);
29882971

29892972
// -ffast-math enables the __FAST_MATH__ preprocessor macro, but check for the

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4245,13 +4245,8 @@ static bool ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
42454245
// Always avoid lexing editor placeholders when we're just running the
42464246
// preprocessor as we never want to emit the
42474247
// "editor placeholder in source file" error in PP only mode.
4248-
// Certain predefined macros which depend upon semantic processing,
4249-
// for example __FLT_EVAL_METHOD__, are not expanded in PP mode, they
4250-
// appear in the preprocessed output as an unexpanded macro name.
4251-
if (isStrictlyPreprocessorAction(Action)) {
4248+
if (isStrictlyPreprocessorAction(Action))
42524249
Opts.LexEditorPlaceholders = false;
4253-
Opts.LexExpandSpecialBuiltins = false;
4254-
}
42554250

42564251
return Diags.getNumErrors() == NumErrorsBefore;
42574252
}

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,8 +1084,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
10841084
}
10851085

10861086
// Macros to control C99 numerics and <float.h>
1087-
// Note: __FLT_EVAL_METHOD__ is not defined here since it is a special
1088-
// builtin macro, its value may fluctuate during compilation.
1087+
Builder.defineMacro("__FLT_EVAL_METHOD__", Twine(TI.getFloatEvalMethod()));
10891088
Builder.defineMacro("__FLT_RADIX__", "2");
10901089
Builder.defineMacro("__DECIMAL_DIG__", "__LDBL_DECIMAL_DIG__");
10911090

clang/lib/Lex/PPMacroExpansion.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,6 @@ void Preprocessor::RegisterBuiltinMacros() {
345345
Ident__TIME__ = RegisterBuiltinMacro(*this, "__TIME__");
346346
Ident__COUNTER__ = RegisterBuiltinMacro(*this, "__COUNTER__");
347347
Ident_Pragma = RegisterBuiltinMacro(*this, "_Pragma");
348-
if (PPOpts->LexExpandSpecialBuiltins)
349-
// Suppress macro expansion if compiler stops before semantic analysis,
350-
// the macro identifier will appear in the preprocessed output.
351-
Ident__FLT_EVAL_METHOD__ =
352-
RegisterBuiltinMacro(*this, "__FLT_EVAL_METHOD__");
353348

354349
// C++ Standing Document Extensions.
355350
if (getLangOpts().CPlusPlus)
@@ -1605,10 +1600,6 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
16051600
// Surround the string with " and strip the trailing newline.
16061601
OS << '"' << StringRef(Result).drop_back() << '"';
16071602
Tok.setKind(tok::string_literal);
1608-
} else if (II == Ident__FLT_EVAL_METHOD__) {
1609-
// __FLT_EVAL_METHOD__ expands to a simple numeric value.
1610-
OS << getCurrentFPEvalMethod();
1611-
Tok.setKind(tok::numeric_constant);
16121603
} else if (II == Ident__COUNTER__) {
16131604
// __COUNTER__ expands to a simple numeric value.
16141605
OS << CounterValue++;
@@ -1706,7 +1697,8 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
17061697

17071698
return false;
17081699
});
1709-
} else if (II == Ident__has_cpp_attribute || II == Ident__has_c_attribute) {
1700+
} else if (II == Ident__has_cpp_attribute ||
1701+
II == Ident__has_c_attribute) {
17101702
bool IsCXX = II == Ident__has_cpp_attribute;
17111703
EvaluateFeatureLikeBuiltinMacro(
17121704
OS, Tok, II, *this, [&](Token &Tok, bool &HasLexedNextToken) -> int {
@@ -1733,7 +1725,8 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
17331725
getLangOpts())
17341726
: 0;
17351727
});
1736-
} else if (II == Ident__has_include || II == Ident__has_include_next) {
1728+
} else if (II == Ident__has_include ||
1729+
II == Ident__has_include_next) {
17371730
// The argument to these two builtins should be a parenthesized
17381731
// file name string literal using angle brackets (<>) or
17391732
// double-quotes ("").

0 commit comments

Comments
 (0)