llvm::getPointerAtOffset

Find a trivial pointer located at a byte offset within a constant.

Synopsis

Declared in <llvm/Analysis/TypeMetadataUtils.h>

Constant*
getPointerAtOffset(
    Constant* I,
    uint64_t Offset,
    Module& M,
    Constant* TopLevelGlobal = nullptr);

Description

Processes a Constant recursively looking into elements of arrays, structs and expressions to find a trivial pointer element that is located at the given offset (relative to the beginning of the whole outer Constant).

Used for example from GlobalDCE to find an entry in a C++ vtable that matches a vcall offset.

To support relative vtables, getPointerAtOffset can see through "relative pointers", i.e. (sub-)expressions of the form of:

symbol = ... { i32 trunc (i64 sub ( i64 ptrtoint (<type> target to i64), i64 ptrtoint (... symbol to i64) ) to i32) }

For such (sub-)expressions, getPointerAtOffset returns the target pointer.

Return Value

The trivial pointer at Offset, or nullptr if none is found.

Parameters

NameDescription
IConstant to search for a pointer at Offset.
OffsetByte offset from the start of I at which to look.
MModule providing the data layout for layout calculations.
TopLevelGlobalOptional top-level global used to validate relative pointer bases; may be nullptr.