From 36b525feb03846c09a4dc56afc92a372704e3171 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Thu, 4 Dec 2014 22:45:31 +0000 Subject: [PATCH] Fix UBSan report in StringMap implementation. Use offsetof() instead of a member access within null pointer. llvm-svn: 223402 --- llvm/include/llvm/ADT/StringMap.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/llvm/include/llvm/ADT/StringMap.h b/llvm/include/llvm/ADT/StringMap.h index 2feb2ab0074d..06afe8426919 100644 --- a/llvm/include/llvm/ADT/StringMap.h +++ b/llvm/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) {