From c0d77e80acb64a534199330018dfc2c92b420c88 Mon Sep 17 00:00:00 2001 From: JF Bastien Date: Tue, 11 Sep 2018 04:52:21 +0000 Subject: [PATCH] NCF: use bit_cast in IntervalMap This use is sketchy because it basically reinterprets a pointer to another pointer, but right now it's hiding in a union. After this change it'll be easy to grep for bit_cast of a pointer and un-sketch things if we want. This patch therefore obeys the law of conservation of sketch, with minor improvement. llvm-svn: 341900 --- llvm/include/llvm/ADT/IntervalMap.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/llvm/include/llvm/ADT/IntervalMap.h b/llvm/include/llvm/ADT/IntervalMap.h index f713668..e2fced1 100644 --- a/llvm/include/llvm/ADT/IntervalMap.h +++ b/llvm/include/llvm/ADT/IntervalMap.h @@ -101,6 +101,7 @@ #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/bit.h" #include "llvm/Support/AlignOf.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/RecyclingAllocator.h" @@ -977,15 +978,10 @@ private: // Allocator used for creating external nodes. Allocator &allocator; - /// dataAs - Represent data as a node type without breaking aliasing rules. + /// Represent data as a node type without breaking aliasing rules. template T &dataAs() const { - union { - const char *d; - T *t; - } u; - u.d = data.buffer; - return *u.t; + return *bit_cast(const_cast(data.buffer)); } const RootLeaf &rootLeaf() const { -- 2.7.4