[llvm-dev] Best way of implement a fat pointer for C

Jacob Lifshay via llvm-dev llvm-dev at lists.llvm.org
Mon Jan 6 21:20:03 PST 2020


On Mon, Jan 6, 2020, 18:45 Jie Zhou via llvm-dev <llvm-dev at lists.llvm.org>
wrote:

> Dear All,
>
<snip>
>
Can you give me some advice on how to implement
> a fat pointer in llvm?
>

Rustc currently implements fat pointers in function arguments by passing a
pair of arguments: the pointer to the object's data and the associated data
which is either the length as a usize (C's uintptr_t) or a pointer to the
vtable. Fat pointers in return values are passed as a two-member struct
where the first member is the pointer to the object's data and the second
is the length or vtable pointer.

See https://rust.godbolt.org/z/cjoRNG for the (definitely non-idiomatic)
rust source code as well as the LLVM IR.

Btw, you should definitely check out Rust if you haven't already at
https://www.rust-lang.org/

Jacob Lifshay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200106/deab3222/attachment.html>


More information about the llvm-dev mailing list