I am trying to understand the LLVM IR generated from a C++ program
int add(int *x);
int func()
{
int T;
T=25;
return add(&T);
}
The generated IR is:
define i32 @_Z4funcv() local_unnamed_addr #0 {
entry:
%T = alloca i32, align 4
%0 = bitcast i32* %T to i8*
call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %0) #3
store i32 25, i32* %T, align 4, !tbaa !2
%call = call i32 @_Z3addPi(i32* nonnull %T)
call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %0) #3
ret i32 %call
}
I do not understand this line %0 = bitcast i32* %T to i8*
. What is the purpose of converting %T
from i32
to i8
?
@llvm.lifetime.start
intrinsic that signifies that till that point in the function (i.e. before the followingstore
) the pointer is dead. You can have a look at the doc and in the LLVM source code for example uses. – Hamish