Find a trivial pointer located at a byte offset within a constant.
Declared in <llvm/Analysis/TypeMetadataUtils.h>
Constant*
getPointerAtOffset(
Constant* I,
uint64_t Offset,
Module& M,
Constant* TopLevelGlobal = nullptr);
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.
The trivial pointer at Offset, or nullptr if none is found.
| Name | Description |
|---|---|
| I | Constant to search for a pointer at Offset. |
| Offset | Byte offset from the start of I at which to look. |
| M | Module providing the data layout for layout calculations. |
| TopLevelGlobal | Optional top-level global used to validate relative pointer bases; may be nullptr. |