[llvm] [IR] Avoid UB in `SymbolTableListTraits` (PR #139096)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Thu May 29 11:03:10 PDT 2025


================
@@ -77,10 +77,8 @@ class SymbolTableListTraits : public ilist_alloc_traits<ValueSubClass> {
   /// getListOwner - Return the object that owns this list.  If this is a list
   /// of instructions, it returns the BasicBlock that owns them.
   ItemParentClass *getListOwner() {
-    size_t Offset = reinterpret_cast<size_t>(
-        &((ItemParentClass *)nullptr->*ItemParentClass::getSublistAccess(
-                                           static_cast<ValueSubClass *>(
-                                               nullptr))));
+    size_t Offset = ItemParentClass::getSublistOffset(
+        static_cast<ValueSubClass *>(nullptr));
     ListTy *Anchor = static_cast<ListTy *>(this);
     return reinterpret_cast<ItemParentClass*>(reinterpret_cast<char*>(Anchor)-
----------------
efriedma-quic wrote:

I'm not sure C++ semantics actually allow this arithmetic, strictly speaking; you might need to go though uintptr_t.  But I don't want to try to address that in this patch.

https://github.com/llvm/llvm-project/pull/139096


More information about the llvm-commits mailing list