[llvm] r342759 - [NFC] use bit_cast in PointerSumType

JF Bastien via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 21 11:35:32 PDT 2018


Author: jfb
Date: Fri Sep 21 11:35:32 2018
New Revision: 342759

URL: http://llvm.org/viewvc/llvm-project?rev=342759&view=rev
Log:
[NFC] use bit_cast in PointerSumType

The code was already using union and memcpy to do this. Remove the memcpy. We can't just change the union because a reference to its member is returned.

Modified:
    llvm/trunk/include/llvm/ADT/PointerSumType.h

Modified: llvm/trunk/include/llvm/ADT/PointerSumType.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/PointerSumType.h?rev=342759&r1=342758&r2=342759&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/PointerSumType.h (original)
+++ llvm/trunk/include/llvm/ADT/PointerSumType.h Fri Sep 21 11:35:32 2018
@@ -10,6 +10,7 @@
 #ifndef LLVM_ADT_POINTERSUMTYPE_H
 #define LLVM_ADT_POINTERSUMTYPE_H
 
+#include "llvm/ADT/bit.h"
 #include "llvm/ADT/DenseMapInfo.h"
 #include "llvm/Support/PointerLikeTypeTraits.h"
 #include <cassert>
@@ -186,11 +187,9 @@ public:
   }
 
   uintptr_t getOpaqueValue() const {
-    uintptr_t Value;
     // Read the underlying storage of the union, regardless of the active
     // member.
-    memcpy(&Value, &Storage, sizeof(Value));
-    return Value;
+    return bit_cast<uintptr_t>(Storage);
   }
 
 protected:




More information about the llvm-commits mailing list