aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-04-22 20:20:28 +0000
committerChris Lattner <sabre@nondot.org>2003-04-22 20:20:28 +0000
commit7a5a1f790f7a3912a9963c11f720b37ebb65056a (patch)
tree6fb2106ddbfcde6a66a9b5df37ae75fc0f0086fa /lib
parent8829dcd15b6b5b198c9a797bfd682c31df44025b (diff)
Use a union to cast int to fp
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5849 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/AsmParser/Lexer.l16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/AsmParser/Lexer.l b/lib/AsmParser/Lexer.l
index 92d4f3424f..85852e2851 100644
--- a/lib/AsmParser/Lexer.l
+++ b/lib/AsmParser/Lexer.l
@@ -73,15 +73,17 @@ static uint64_t HexIntToVal(const char *Buffer) {
// point representation of it.
//
static double HexToFP(const char *Buffer) {
- uint64_t Result = HexIntToVal(Buffer);
-
- assert(sizeof(double) == sizeof(Result) &&
- "Data sizes incompatible on this target!");
// Behave nicely in the face of C TBAA rules... see:
// http://www.nullstone.com/htmls/category/aliastyp.htm
- //
- char *ProxyPointer = (char*)&Result;
- return *(double*)ProxyPointer; // Cast Hex constant to double
+ union {
+ uint64_t UI;
+ double FP;
+ } UIntToFP;
+ UIntToFP.UI = HexIntToVal(Buffer);
+
+ assert(sizeof(double) == sizeof(uint64_t) &&
+ "Data sizes incompatible on this target!");
+ return UIntToFP.FP; // Cast Hex constant to double
}