From: Alexey Samsonov Date: Thu, 4 Dec 2014 22:45:31 +0000 (+0000) Subject: Fix UBSan report in StringMap implementation. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=8bc006707164952c3b0fc4dcc4f7c3d68e34c4ab;p=oota-llvm.git Fix UBSan report in StringMap implementation. Use offsetof() instead of a member access within null pointer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223402 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ADT/StringMap.h b/include/llvm/ADT/StringMap.h index 2feb2ab0074..06afe842691 100644 --- a/include/llvm/ADT/StringMap.h +++ b/include/llvm/ADT/StringMap.h @@ -182,10 +182,7 @@ public: /// GetStringMapEntryFromValue - Given a value that is known to be embedded /// into a StringMapEntry, return the StringMapEntry itself. static StringMapEntry &GetStringMapEntryFromValue(ValueTy &V) { - StringMapEntry *EPtr = 0; - char *Ptr = reinterpret_cast(&V) - - (reinterpret_cast(&EPtr->second) - - reinterpret_cast(EPtr)); + char *Ptr = reinterpret_cast(&V) - offsetof(StringMapEntry, second); return *reinterpret_cast(Ptr); } static const StringMapEntry &GetStringMapEntryFromValue(const ValueTy &V) {