aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-01-04 01:56:57 +0000
committerChris Lattner <sabre@nondot.org>2005-01-04 01:56:57 +0000
commit71d94d16b6011b4e9be69678addb9265a6c65266 (patch)
tree2e0d5baebfbf6bdb8dc94fd9cc65dedb0fd70625
parent67cb2f6eb5e515c25bf559bb3d5ef6fea05fd8b6 (diff)
To not break TBAA rules, use a union.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19280 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/VMCore/AsmWriter.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index 945f0b5b6c..d5a8a5c601 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -421,7 +421,8 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV,
(StrVal[1] >= '0' && StrVal[1] <= '9')))
// Reparse stringized version!
if (atof(StrVal.c_str()) == CFP->getValue()) {
- Out << StrVal; return;
+ Out << StrVal;
+ return;
}
// Otherwise we could not reparse it to exactly the same value, so we must
@@ -430,11 +431,14 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV,
// Behave nicely in the face of C TBAA rules... see:
// http://www.nullstone.com/htmls/category/aliastyp.htm
//
- double Val = CFP->getValue();
- char *Ptr = (char*)&Val;
- assert(sizeof(double) == sizeof(uint64_t) && sizeof(double) == 8 &&
+ union {
+ double D;
+ uint64_t U;
+ } V;
+ V.D = CFP->getValue();
+ assert(sizeof(double) == sizeof(uint64_t) &&
"assuming that double is 64 bits!");
- Out << "0x" << utohexstr(*(uint64_t*)Ptr);
+ Out << "0x" << utohexstr(V.U);
} else if (isa<ConstantAggregateZero>(CV)) {
Out << "zeroinitializer";