[PATCH] D124004: Define __FLT_EVAL_METHOD__ when input source is stdin.

Zahira Ammarguellat via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 19 07:05:42 PDT 2022


zahiraam created this revision.
zahiraam added reviewers: aaron.ballman, andrew.w.kaylor.
Herald added a subscriber: dschuff.
Herald added a project: All.
zahiraam requested review of this revision.
Herald added a subscriber: aheejin.
Herald added a project: clang.

When the input source is stdin, the __FLT_EVAL_METHOD__ macro is not  set. 
This patch defines it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124004

Files:
  clang/lib/Frontend/FrontendAction.cpp
  clang/test/Preprocessor/flt_eval_macro.cpp
  clang/test/Preprocessor/init.c


Index: clang/test/Preprocessor/init.c
===================================================================
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -1571,6 +1571,7 @@
 // WEBASSEMBLY-NEXT:#define __FLT_DENORM_MIN__ 1.40129846e-45F
 // WEBASSEMBLY-NEXT:#define __FLT_DIG__ 6
 // WEBASSEMBLY-NEXT:#define __FLT_EPSILON__ 1.19209290e-7F
+// WEBASSEMBLY-NEXT:#define __FLT_EVAL_METHOD__ 0
 // WEBASSEMBLY-NEXT:#define __FLT_HAS_DENORM__ 1
 // WEBASSEMBLY-NEXT:#define __FLT_HAS_INFINITY__ 1
 // WEBASSEMBLY-NEXT:#define __FLT_HAS_QUIET_NAN__ 1
Index: clang/test/Preprocessor/flt_eval_macro.cpp
===================================================================
--- clang/test/Preprocessor/flt_eval_macro.cpp
+++ clang/test/Preprocessor/flt_eval_macro.cpp
@@ -23,6 +23,31 @@
 // RUN:   -target-feature -sse %s -o - | FileCheck -check-prefix=EXT %s \
 // RUN:   -strict-whitespace
 
+// RUN: %clang_cc1 -E -dM -triple=x86_64-none-none  < /dev/null \
+// RUN:   | FileCheck %s  --check-prefix=CHECK-FEM
+
+// RUN: %clang_cc1 -E -dM -triple=x86_64-none-none -target-feature -sse \
+// RUN:   < /dev/null | FileCheck %s  --check-prefix=CHECK-FEM-EXT
+
+// RUN: %clang_cc1 -E -dM -triple=arm64e-apple-ios -target-feature -sse \
+// RUN:   < /dev/null | FileCheck %s  --check-prefix=CHECK-FEM
+
+// RUN: %clang_cc1 -E -dM -triple=arm64e-apple-ios -target-feature +sse \
+// RUN:   < /dev/null | FileCheck %s  --check-prefix=CHECK-FEM
+
+// RUN: %clang_cc1 -E -dM -triple=arm64_32-apple-ios < /dev/null \
+// RUN:   | FileCheck %s  --check-prefix=CHECK-FEM
+
+// RUN: %clang_cc1 -E -dM -triple=arm64_32-apple-ios -target-feature -sse \
+// RUN:   < /dev/null | FileCheck %s  --check-prefix=CHECK-FEM
+
+// RUN: %clang_cc1 -E -dM -triple i386-pc-windows -target-cpu pentium4 \
+// RUN:   < /dev/null | FileCheck %s  --check-prefix=CHECK-FEM
+
+// RUN: %clang_cc1 -E -dM -triple i386-pc-windows -target-cpu pentium4 \
+// RUN:   -target-feature -sse < /dev/null \
+// RUN:   | FileCheck %s  --check-prefix=CHECK-FEM-EXT
+
 #ifdef __FLT_EVAL_METHOD__
 #if __FLT_EVAL_METHOD__ == 3
 #define __GLIBC_FLT_EVAL_METHOD 2
@@ -80,3 +105,6 @@
   // EXT: #define Val "val2"
   return Val;
 }
+
+// CHECK-FEM: #define __FLT_EVAL_METHOD__ 0
+// CHECK-FEM-EXT: #define __FLT_EVAL_METHOD__ 2
Index: clang/lib/Frontend/FrontendAction.cpp
===================================================================
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/DeclGroup.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/LangStandard.h"
+#include "clang/Basic/MacroBuilder.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
@@ -840,6 +841,19 @@
     CI.getLangOpts().CurrentModule = CI.getLangOpts().ModuleName;
   }
 
+  // Set the __FLT_EVAL_METHOD__ when the input source is stdin.
+  if (Input.isFile() && Input.getFile() == "-") {
+    Preprocessor &PP = CI.getPreprocessor();
+    std::string PredefineBuffer;
+    PredefineBuffer.reserve(4080);
+    llvm::raw_string_ostream Predefines(PredefineBuffer);
+    Predefines << PP.getPredefines();
+    MacroBuilder Builder(Predefines);
+    Builder.append("# 1 \"<built-in>\" 3");
+    Builder.defineMacro("__FLT_EVAL_METHOD__", Twine(PP.getTUFPEvalMethod()));
+    PP.setPredefines(Predefines.str());
+  }
+
   if (!CI.InitializeSourceManager(Input))
     return false;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124004.423614.patch
Type: text/x-patch
Size: 3491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220419/a3bd0d09/attachment.bin>


More information about the cfe-commits mailing list