Skip to content

Commit fce3e75

Browse files
zahiraamtstellar
authored andcommitted
Revert "Currently the control of the eval-method is mixed with fast-math."
Setting __FLT_EVAL_METHOD__ to -1 with fast-math will set __GLIBC_FLT_EVAL_METHOD to 2 and long double ends up being used for float_t and double_t. This creates some ABI breakage with various C libraries. See details here: #60781 This reverts commit bbf0d19. (cherry picked from commit 2f12642)
1 parent a9e129e commit fce3e75

File tree

7 files changed

+10
-184
lines changed

7 files changed

+10
-184
lines changed

clang/include/clang/Lex/Preprocessor.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,6 @@ class Preprocessor {
193193
LangOptions::FPEvalMethodKind CurrentFPEvalMethod =
194194
LangOptions::FPEvalMethodKind::FEM_UnsetOnCommandLine;
195195

196-
// Keeps the value of the last evaluation method before a
197-
// `pragma float_control (precise,off) is applied.
198-
LangOptions::FPEvalMethodKind LastFPEvalMethod =
199-
LangOptions::FPEvalMethodKind::FEM_UnsetOnCommandLine;
200-
201196
// The most recent pragma location where the floating point evaluation
202197
// method was modified. This is used to determine whether the
203198
// 'pragma clang fp eval_method' was used whithin the current scope.
@@ -2335,14 +2330,6 @@ class Preprocessor {
23352330
return LastFPEvalPragmaLocation;
23362331
}
23372332

2338-
LangOptions::FPEvalMethodKind getLastFPEvalMethod() const {
2339-
return LastFPEvalMethod;
2340-
}
2341-
2342-
void setLastFPEvalMethod(LangOptions::FPEvalMethodKind Val) {
2343-
LastFPEvalMethod = Val;
2344-
}
2345-
23462333
void setCurrentFPEvalMethod(SourceLocation PragmaLoc,
23472334
LangOptions::FPEvalMethodKind Val) {
23482335
assert(Val != LangOptions::FEM_UnsetOnCommandLine &&

clang/lib/Lex/PPMacroExpansion.cpp

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,35 +1637,14 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
16371637
Tok.setKind(tok::string_literal);
16381638
} else if (II == Ident__FLT_EVAL_METHOD__) {
16391639
// __FLT_EVAL_METHOD__ is set to the default value.
1640-
if (getTUFPEvalMethod() ==
1641-
LangOptions::FPEvalMethodKind::FEM_Indeterminable) {
1642-
// This is possible if `AllowFPReassoc` or `AllowReciprocal` is enabled.
1643-
// These modes can be triggered via the command line option `-ffast-math`
1644-
// or via a `pragam float_control`.
1645-
// __FLT_EVAL_METHOD__ expands to -1.
1646-
// The `minus` operator is the next token we read from the stream.
1647-
auto Toks = std::make_unique<Token[]>(1);
1648-
OS << "-";
1649-
Tok.setKind(tok::minus);
1650-
// Push the token `1` to the stream.
1651-
Token NumberToken;
1652-
NumberToken.startToken();
1653-
NumberToken.setKind(tok::numeric_constant);
1654-
NumberToken.setLiteralData("1");
1655-
NumberToken.setLength(1);
1656-
Toks[0] = NumberToken;
1657-
EnterTokenStream(std::move(Toks), 1, /*DisableMacroExpansion*/ false,
1658-
/*IsReinject*/ false);
1659-
} else {
1660-
OS << getTUFPEvalMethod();
1661-
// __FLT_EVAL_METHOD__ expands to a simple numeric value.
1662-
Tok.setKind(tok::numeric_constant);
1663-
if (getLastFPEvalPragmaLocation().isValid()) {
1664-
// The program is ill-formed. The value of __FLT_EVAL_METHOD__ is
1665-
// altered by the pragma.
1666-
Diag(Tok, diag::err_illegal_use_of_flt_eval_macro);
1667-
Diag(getLastFPEvalPragmaLocation(), diag::note_pragma_entered_here);
1668-
}
1640+
OS << getTUFPEvalMethod();
1641+
// __FLT_EVAL_METHOD__ expands to a simple numeric value.
1642+
Tok.setKind(tok::numeric_constant);
1643+
if (getLastFPEvalPragmaLocation().isValid()) {
1644+
// The program is ill-formed. The value of __FLT_EVAL_METHOD__ is altered
1645+
// by the pragma.
1646+
Diag(Tok, diag::err_illegal_use_of_flt_eval_macro);
1647+
Diag(getLastFPEvalPragmaLocation(), diag::note_pragma_entered_here);
16691648
}
16701649
} else if (II == Ident__COUNTER__) {
16711650
// __COUNTER__ expands to a simple numeric value.

clang/lib/Lex/Preprocessor.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,6 @@ void Preprocessor::Initialize(const TargetInfo &Target,
207207
else
208208
// Set initial value of __FLT_EVAL_METHOD__ from the command line.
209209
setCurrentFPEvalMethod(SourceLocation(), getLangOpts().getFPEvalMethod());
210-
// When `-ffast-math` option is enabled, it triggers several driver math
211-
// options to be enabled. Among those, only one the following two modes
212-
// affect the eval-method: reciprocal or reassociate.
213-
if (getLangOpts().AllowFPReassoc || getLangOpts().AllowRecip)
214-
setCurrentFPEvalMethod(SourceLocation(), LangOptions::FEM_Indeterminable);
215210
}
216211

217212
void Preprocessor::InitializeForModelFile() {

clang/lib/Sema/SemaAttr.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -565,13 +565,6 @@ void Sema::ActOnPragmaFloatControl(SourceLocation Loc,
565565
case PFC_Precise:
566566
NewFPFeatures.setFPPreciseEnabled(true);
567567
FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
568-
if (PP.getCurrentFPEvalMethod() ==
569-
LangOptions::FPEvalMethodKind::FEM_Indeterminable &&
570-
PP.getLastFPEvalPragmaLocation().isValid())
571-
// A preceding `pragma float_control(precise,off)` has changed
572-
// the value of the evaluation method.
573-
// Set it back to its old value.
574-
PP.setCurrentFPEvalMethod(SourceLocation(), PP.getLastFPEvalMethod());
575568
break;
576569
case PFC_NoPrecise:
577570
if (CurFPFeatures.getExceptionMode() == LangOptions::FPE_Strict)
@@ -581,10 +574,6 @@ void Sema::ActOnPragmaFloatControl(SourceLocation Loc,
581574
else
582575
NewFPFeatures.setFPPreciseEnabled(false);
583576
FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
584-
PP.setLastFPEvalMethod(PP.getCurrentFPEvalMethod());
585-
// `AllowFPReassoc` or `AllowReciprocal` option is enabled.
586-
PP.setCurrentFPEvalMethod(
587-
Loc, LangOptions::FPEvalMethodKind::FEM_Indeterminable);
588577
break;
589578
case PFC_Except:
590579
if (!isPreciseFPEnabled())
@@ -608,12 +597,6 @@ void Sema::ActOnPragmaFloatControl(SourceLocation Loc,
608597
}
609598
FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
610599
NewFPFeatures = FpPragmaStack.CurrentValue;
611-
if (CurFPFeatures.getAllowFPReassociate() ||
612-
CurFPFeatures.getAllowReciprocal())
613-
// Since we are popping the pragma, we don't want to be passing
614-
// a location here.
615-
PP.setCurrentFPEvalMethod(SourceLocation(),
616-
CurFPFeatures.getFPEvalMethod());
617600
break;
618601
}
619602
CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());

clang/test/CodeGen/X86/fexcess-precision.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ _Float16 f(_Float16 a, _Float16 b, _Float16 c, _Float16 d) {
380380
//
381381
// CHECK-UNSAFE-LABEL: @getFEM(
382382
// CHECK-UNSAFE-NEXT: entry:
383-
// CHECK-UNSAFE-NEXT: ret i32 -1
383+
// CHECK-UNSAFE-NEXT: ret i32 0
384384
//
385385
int getFEM() {
386386
return __FLT_EVAL_METHOD__;

clang/test/CodeGen/eval-method-fast-math.cpp

Lines changed: 0 additions & 117 deletions
This file was deleted.

clang/test/Preprocessor/flt_eval_macro.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// RUN: %s -o - | FileCheck %s -strict-whitespace
1818

1919
// RUN: %clang_cc1 -E -dM -triple=x86_64-apple-macos13.0 -ffast-math \
20-
// RUN: %s -o - | FileCheck %s -check-prefix=CHECK-MINUS-ONE -strict-whitespace
20+
// RUN: %s -o - | FileCheck %s -check-prefix=CHECK -strict-whitespace
2121

2222
// RUN: %clang_cc1 -E -dM -triple i386-pc-windows -target-cpu pentium4 %s -o - \
2323
// RUN: | FileCheck %s -strict-whitespace
@@ -64,7 +64,6 @@
6464

6565
int foo() {
6666
// CHECK: #define Name "One"
67-
// CHECK-MINUS-ONE: #define Name "MinusOne"
6867
// EXT: #define Name "Three"
6968
return Name;
7069
}

0 commit comments

Comments
 (0)