diff options
author | Chris Lattner <sabre@nondot.org> | 2002-04-07 08:37:11 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-04-07 08:37:11 +0000 |
commit | ace9103ebefcece3e26c69735dd0087bb973579c (patch) | |
tree | 45100dc9ba58bb3d1817f0aac808995f2ab7ee6a | |
parent | 35c15b4bfe2de7205bbb35790a3418d7d3288156 (diff) |
Fix bug: test/Regression/Other/2002-04-07-HexFloatConstants.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2141 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/VMCore/Constants.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index d9a2fa7431..410276683d 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -13,7 +13,6 @@ #include "llvm/Analysis/SlotCalculator.h" #include "Support/StringExtras.h" #include <algorithm> -#include <assert.h> using std::map; using std::pair; @@ -159,8 +158,27 @@ std::string ConstantUInt::getStrValue() const { return utostr(Val.Unsigned); } +// ConstantFP::getStrValue - We would like to output the FP constant value in +// exponential notation, but we cannot do this if doing so will lose precision. +// Check here to make sure that we only output it in exponential format if we +// can parse the value back and get the same value. +// std::string ConstantFP::getStrValue() const { - return ftostr(Val); + std::string StrVal = ftostr(Val); + double TestVal = atof(StrVal.c_str()); // Reparse stringized version! + if (TestVal == Val) + return StrVal; + + // Otherwise we could not reparse it to exactly the same value, so we must + // output the string in hexadecimal format! + // + // Behave nicely in the face of C TBAA rules... see: + // http://www.nullstone.com/htmls/category/aliastyp.htm + // + char *Ptr = (char*)&Val; + assert(sizeof(double) == sizeof(uint64_t) && sizeof(double) == 8 && + "assuming that double is 64 bits!"); + return "0x"+utohexstr(*(uint64_t*)Ptr); } std::string ConstantArray::getStrValue() const { |