From 4eca27141d5f36e92e60e341a53c3e35de7c24b4 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 13 Feb 2013 04:53:40 +0000 Subject: [PATCH] use memcpy instead of dubious union to type pun two values, thanks to David Blaike for pointing this out. llvm-svn: 175032 --- include/llvm/Bitcode/BitstreamReader.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/include/llvm/Bitcode/BitstreamReader.h b/include/llvm/Bitcode/BitstreamReader.h index edec6e1da51..2d2976cde13 100644 --- a/include/llvm/Bitcode/BitstreamReader.h +++ b/include/llvm/Bitcode/BitstreamReader.h @@ -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 - 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 + EndianValue; + memcpy(&EndianValue, Array, sizeof(Array)); + + CurWord = EndianValue; NextChar += sizeof(word_t);