Looks like a pointer indeed.
EDIT: from the point of view of Rust, person
contains the actual struct
, so in the Rust code let person = Person{age : 52};
the variable person
is not a pointer and doesn't contain a pointer. However, it could be implemented as a pointer, as the LLVM IR below shows. Thus, the Rust code could be translated to LLVM IR where %person
will indeed be a pointer to the first element of the struct. Note that this IR can be optimised in such a way that the actual data could end up in a register, so not necessarily on the stack.
The LLVM IR for main
looks like this:
; playground::main
; Function Attrs: nonlazybind uwtable
define internal void @_ZN10playground4main17h5b277f290810a924E() unnamed_addr #1 !dbg !315 {
start:
%arg0.dbg.spill = alloca i32*, align 8
%_11 = alloca i32*, align 8
%_10 = alloca [1 x { i8*, i64* }], align 8
%_3 = alloca %"std::fmt::Arguments", align 8
%person = alloca i32, align 4
call void @llvm.dbg.declare(metadata i32* %person, metadata !319, metadata !DIExpression()), !dbg !328
store i32 52, i32* %person, align 4, !dbg !329
// ...
}
%person = alloca i32, align 4
allocates space for an i32
on the stack and returns a pointer (so person
is a pointer)
store i32 52, i32* %person, align 4
stores the integer 52
into that pointer. The code i32* %person
says that %person
is of type i32*
, so again a pointer to an integer.
If you change the struct to look like struct Person { age: i32, thing: bool }
, for example, the corresponding IR would be %person = alloca { i32, i8 }, align 4
, so now it's a pointer to a struct of type { i32, i8 }
.
Now storing the integer 52 would require some casting:
%0 = bitcast { i32, i8 }* %person to i32* // cast %person to i32*
store i32 52, i32* %0, align 4