Skip to content

Support addrspacecast instructions (introduced in LLVM 3.4) #346

@RyanGlScott

Description

@RyanGlScott

LLVM 3.4 adds an addrspacecast instruction (see llvm/llvm-project@b03bd4d for the commit which introduces this). Per the LLVM Language Reference:

The 'addrspacecast' instruction converts the pointer value ptrval to type pty2. It can be a no-op cast or a complex value modification, depending on the target and the address space pair. Pointer conversions within the same address space must be performed with the bitcast instruction. Note that if the address space conversion produces a dereferenceable result then both result and operand refer to the same memory location. The conversion must have no side effects, and must not capture the value of the pointer.

Note that tools like Crucible currently do not track address spaces, so Crucible's semantics for addrspacecast could simply be a no-op.

The following C program (adapted from this Clang test case) causes Clang to emit an addrspacecast instruction:

// test.c
__attribute((address_space(1))) __attribute__((annotate("addrspace1_ann"))) char addrspace1_var;

When compiled with clang -g -emit-llvm test.c -c, this will produce LLVM bitcode that 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 0 of record Record {recordCode = 11, recordFields = [FieldFixed (BitString {bsLength = NumBits 4, bsData = 12}),FieldFixed (BitString {bsLength = NumBits 4, bsData = 0}),FieldVBR (BitString {bsLength = NumBits 7, bsData = 0})]}
from:
	CST_CODE_CE_CAST
	CONSTANTS_BLOCK
	value symbol table
	MODULE_BLOCK
	Bitstream

Adding support for addrspacecast could be done independently of adding more general support for address spaces (see GaloisInc/llvm-pretty#147).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions