From b406669fea7c8db83a377f368f1689c848296974 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Wed, 28 Dec 2011 15:47:06 +0000 Subject: [PATCH] Add a target hook for FLT_EVAL_METHOD and use it to set the value on x86 with sse disabled. x87 math evaluates everything with 80 bits precision, so we have to set FLT_EVAL_METHOD to "2". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147311 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/TargetInfo.h | 3 +++ lib/Basic/Targets.cpp | 4 ++++ lib/Frontend/InitPreprocessor.cpp | 2 +- test/Preprocessor/init.c | 4 ++-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index 2805978179..5e219262dd 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -256,6 +256,9 @@ public: return *LongDoubleFormat; } + /// getFloatEvalMethod - Return the value for the C99 FLT_EVAL_METHOD macro. + virtual unsigned getFloatEvalMethod() const { return 0; } + // getLargeArrayMinWidth/Align - Return the minimum array size that is // 'large' and its alignment. unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; } diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 34258c1054..bb1051d740 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -1339,6 +1339,10 @@ public: BigEndian = false; LongDoubleFormat = &llvm::APFloat::x87DoubleExtended; } + virtual unsigned getFloatEvalMethod() const { + // X87 evaluates with 80 bits "long double" precision. + return SSELevel == NoSSE ? 2 : 0; + } virtual void getTargetBuiltins(const Builtin::Info *&Records, unsigned &NumRecords) const { Records = BuiltinInfo; diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index c67eba40b5..f601f3d73a 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -513,7 +513,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI, } // Macros to control C99 numerics and - Builder.defineMacro("__FLT_EVAL_METHOD__", "0"); + Builder.defineMacro("__FLT_EVAL_METHOD__", Twine(TI.getFloatEvalMethod())); Builder.defineMacro("__FLT_RADIX__", "2"); int Dig = PickFP(&TI.getLongDoubleFormat(), -1/*FIXME*/, 17, 21, 33, 36); Builder.defineMacro("__DECIMAL_DIG__", Twine(Dig)); diff --git a/test/Preprocessor/init.c b/test/Preprocessor/init.c index ec90d6a3bb..d890d4af93 100644 --- a/test/Preprocessor/init.c +++ b/test/Preprocessor/init.c @@ -242,7 +242,7 @@ // I386:#define __FLT_DENORM_MIN__ 1.40129846e-45F // I386:#define __FLT_DIG__ 6 // I386:#define __FLT_EPSILON__ 1.19209290e-7F -// I386:#define __FLT_EVAL_METHOD__ 0 +// I386:#define __FLT_EVAL_METHOD__ 2 // I386:#define __FLT_HAS_DENORM__ 1 // I386:#define __FLT_HAS_INFINITY__ 1 // I386:#define __FLT_HAS_QUIET_NAN__ 1 @@ -315,7 +315,7 @@ // I386:#define __i386__ 1 // I386:#define i386 1 // -// RUN: %clang_cc1 -E -dM -ffreestanding -triple=i386-pc-linux-gnu < /dev/null | FileCheck -check-prefix I386-LINUX %s +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=i386-pc-linux-gnu -target-cpu pentium4 < /dev/null | FileCheck -check-prefix I386-LINUX %s // // I386-LINUX:#define __CHAR16_TYPE__ unsigned short // I386-LINUX:#define __CHAR32_TYPE__ unsigned int -- 2.40.0