[PATCH] D128814: [Clang][Preprocessor] Fix inconsistent `FLT_EVAL_METHOD` when compiling vs preprocessing
Egor Zhdan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 29 06:16:45 PDT 2022
egorzhdan updated this revision to Diff 440978.
egorzhdan added a comment.
Adjust commit message
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128814/new/
https://reviews.llvm.org/D128814
Files:
clang/lib/Lex/Preprocessor.cpp
clang/lib/Sema/Sema.cpp
clang/test/Preprocessor/flt_eval_macro.cpp
Index: clang/test/Preprocessor/flt_eval_macro.cpp
===================================================================
--- clang/test/Preprocessor/flt_eval_macro.cpp
+++ clang/test/Preprocessor/flt_eval_macro.cpp
@@ -16,6 +16,9 @@
// RUN: %clang_cc1 -E -dM -triple=arm64_32-apple-ios -target-feature -sse \
// RUN: %s -o - | FileCheck %s -strict-whitespace
+// RUN: %clang_cc1 -E -dM -triple=x86_64-apple-macos13.0 -ffast-math \
+// RUN: %s -o - | FileCheck %s -check-prefix=CHECK-MINUS-ONE -strict-whitespace
+
// RUN: %clang_cc1 -E -dM -triple i386-pc-windows -target-cpu pentium4 %s -o - \
// RUN: | FileCheck %s -strict-whitespace
@@ -35,7 +38,9 @@
#define __GLIBC_FLT_EVAL_METHOD 2
#endif
-#if __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
+#if __GLIBC_FLT_EVAL_METHOD == -1
+#define Name "MinusOne"
+#elif __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
#define Name "One"
#elif __GLIBC_FLT_EVAL_METHOD == 1
#define Name "Two"
@@ -59,6 +64,7 @@
int foo() {
// CHECK: #define Name "One"
+ // CHECK-MINUS-ONE: #define Name "MinusOne"
// EXT: #define Name "Three"
return Name;
}
Index: clang/lib/Sema/Sema.cpp
===================================================================
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -249,21 +249,8 @@
SemaPPCallbackHandler = Callbacks.get();
PP.addPPCallbacks(std::move(Callbacks));
SemaPPCallbackHandler->set(*this);
- if (getLangOpts().getFPEvalMethod() == LangOptions::FEM_UnsetOnCommandLine)
- // Use setting from TargetInfo.
- PP.setCurrentFPEvalMethod(SourceLocation(),
- ctxt.getTargetInfo().getFPEvalMethod());
- else
- // Set initial value of __FLT_EVAL_METHOD__ from the command line.
- PP.setCurrentFPEvalMethod(SourceLocation(),
- getLangOpts().getFPEvalMethod());
+
CurFPFeatures.setFPEvalMethod(PP.getCurrentFPEvalMethod());
- // When `-ffast-math` option is enabled, it triggers several driver math
- // options to be enabled. Among those, only one the following two modes
- // affect the eval-method: reciprocal or reassociate.
- if (getLangOpts().AllowFPReassoc || getLangOpts().AllowRecip)
- PP.setCurrentFPEvalMethod(SourceLocation(),
- LangOptions::FEM_Indeterminable);
}
// Anchor Sema's type info to this TU.
Index: clang/lib/Lex/Preprocessor.cpp
===================================================================
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -206,6 +206,18 @@
// Initialize the __FTL_EVAL_METHOD__ macro to the TargetInfo.
setTUFPEvalMethod(getTargetInfo().getFPEvalMethod());
+
+ if (getLangOpts().getFPEvalMethod() == LangOptions::FEM_UnsetOnCommandLine)
+ // Use setting from TargetInfo.
+ setCurrentFPEvalMethod(SourceLocation(), Target.getFPEvalMethod());
+ else
+ // Set initial value of __FLT_EVAL_METHOD__ from the command line.
+ setCurrentFPEvalMethod(SourceLocation(), getLangOpts().getFPEvalMethod());
+ // When `-ffast-math` option is enabled, it triggers several driver math
+ // options to be enabled. Among those, only one the following two modes
+ // affect the eval-method: reciprocal or reassociate.
+ if (getLangOpts().AllowFPReassoc || getLangOpts().AllowRecip)
+ setCurrentFPEvalMethod(SourceLocation(), LangOptions::FEM_Indeterminable);
}
void Preprocessor::InitializeForModelFile() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128814.440978.patch
Type: text/x-patch
Size: 3458 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220629/1fd4b5e5/attachment.bin>
More information about the cfe-commits
mailing list