[llvm] CallPromotionUtils: Correctly use IndexSize when determining the bit width of pointer offsets. (PR #119138)

Jessica Clarke via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 10 16:57:47 PST 2024


================
@@ -712,7 +712,7 @@ bool llvm::tryPromoteCall(CallBase &CB) {
       VTablePtrLoad, VTablePtrLoad->getParent(), BBI, 0, nullptr, nullptr);
   if (!VTablePtr)
     return false; // No vtable found.
-  APInt VTableOffsetGVBase(DL.getTypeSizeInBits(VTablePtr->getType()), 0);
----------------
jrtc27 wrote:

Presumably FindAvailableLoadedValue can return a pointer-sized integer (really, anything that CastInst::isBitOrNoopPointerCastable) if you end up storing a uintptr_t that you then load and call. If so, stripAndAccumulateConstantOffsets returns its input for non-pointers and then the dyn_cast will definitely give null.

(Obviously not true on CHERI for various reasons)

The other instances are fine because they're using the pointer operands of loads so by definition are pointers, whereas this one is some random other Value that is known to be the same bit pattern as the value loaded here.

So probably line 713 needs to gain a type check. Maybe you could cast back instead, though I'd worry about provenance due to peeking through inttoptr(ptrtoint(...)), and AFAICT the former would make the new code behave like the old code.

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


More information about the llvm-commits mailing list