-
Notifications
You must be signed in to change notification settings - Fork 7
Description
LLVM 22 adds a ptrtoaddr instruction (see llvm/llvm-project@3a4b351 for the commit which introduces this). Per the LLVM Language Reference:
The ‘
ptrtoaddr’ instruction converts the pointer or a vector of pointers value to the underlying integer address (or vector of addresses) of type ty2. This is different fromptrtointin that it only operates on the index bits of the pointer and ignores all other bits, and does not capture the provenance of the pointer.
Note that tools like Crucible currently do not track pointer provenance, so in that regard, Crucible's semantics for ptrtoint would also suffice for ptrtoaddr.
The commit message which introduces ptrtoaddr explains the following about the parts relating to index bits:
For most architectures, difference 2) [it only operates on the index bits of the pointer] does not matter since index (address) width and pointer representation width are the same, but this does make a difference for architectures that have pointers that aren't just plain integer addresses such as AMDGPU fat pointers or CHERI capabilities.
I am having trouble getting Clang to emit involving ptrtoaddr, but here is a snippet of LLVM code drawn from LLVM's Bitcode/ptrtoaddr.ll test case:
define i64 @test_as0(ptr %p) {
%addr = ptrtoaddr ptr %p to i64
ret i64 %addr
}Currently, llvm-pretty-bc-parser chokes on this:
λ> :m + Text.LLVM.PP Data.LLVM.BitCode
λ> parseBitCodeFromFileWithWarnings "test.bc" >>= either (putStrLn . formatError) (print . ppLLVM llvmVlatest ppModule . fst)
parseField: unable to parse record field 2 of record Record {recordCode = 3, recordFields = [FieldVBR (BitString {bsLength = NumBits 5, bsData = 1}),FieldFixed (BitString {bsLength = NumBits 3, bsData = 1}),FieldFixed (BitString {bsLength = NumBits 4, bsData = 13})]}
from:
FUNC_CODE_INST_CAST
@test_as0
FUNCTION_BLOCK
FUNCTION_BLOCK_ID
value symbol table
MODULE_BLOCK
Bitstream