use memcpy instead of dubious union to type pun two values,
authorChris Lattner <sabre@nondot.org>
Wed, 13 Feb 2013 04:53:40 +0000 (04:53 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 13 Feb 2013 04:53:40 +0000 (04:53 +0000)
thanks to David Blaike for pointing this out.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175032 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Bitcode/BitstreamReader.h

index edec6e1da51a6badfaeb719330ff971e757fb910..2d2976cde13ca867b8a1344c25979a0569203ffa 100644 (file)
@@ -364,16 +364,17 @@ public:
     uint32_t R = uint32_t(CurWord);
 
     // Read the next word from the stream.
-    union {
-      uint8_t ArrayMember[sizeof(word_t)];
-      support::detail::packed_endian_specific_integral
-      <word_t, support::little, support::unaligned> EndianMember;
-    } buf = { { 0 } };
+    uint8_t Array[sizeof(word_t)] = {0};
+    
+    BitStream->getBitcodeBytes().readBytes(NextChar, sizeof(Array),
+                                           Array, NULL);
     
-    BitStream->getBitcodeBytes().readBytes(NextChar, sizeof(buf),
-                                           buf.ArrayMember, NULL);
     // Handle big-endian byte-swapping if necessary.
-    CurWord = buf.EndianMember;
+    support::detail::packed_endian_specific_integral
+      <word_t, support::little, support::unaligned> EndianValue;
+    memcpy(&EndianValue, Array, sizeof(Array));
+    
+    CurWord = EndianValue;
 
     NextChar += sizeof(word_t);