[llvm] r175032 - use memcpy instead of dubious union to type pun two values,

Chris Lattner sabre at nondot.org
Tue Feb 12 20:53:40 PST 2013


Author: lattner
Date: Tue Feb 12 22:53:40 2013
New Revision: 175032

URL: http://llvm.org/viewvc/llvm-project?rev=175032&view=rev
Log:
use memcpy instead of dubious union to type pun two values,
thanks to David Blaike for pointing this out.

Modified:
    llvm/trunk/include/llvm/Bitcode/BitstreamReader.h

Modified: llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitstreamReader.h?rev=175032&r1=175031&r2=175032&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/BitstreamReader.h (original)
+++ llvm/trunk/include/llvm/Bitcode/BitstreamReader.h Tue Feb 12 22:53:40 2013
@@ -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);
 





More information about the llvm-commits mailing list