Hi, all
I am trying to use GEP to get a pointer of i32 from an array.
But the problem is: I don't know the size of the array.
The IR document on
llvm.org said GEP just adds the offsets to the
base address with silently-wrapping two锟斤拷s complement arithmetic.
So, I want to ask for some advice.
Is it safe like this:
%v1 = alloca i32
store i32 5, i32* %v1
%6 = load i32* %v1
%7 = bitcast i32* %v0 to [1 x i32]*
%8 = getelementptr [1 x i32]* %7, i32 0, i32 %6
%9 = load i32* %8
store i32 %9, i32* %v0
Type of %v0 is i32*, and I know %v0 is pointing to an array in mem,
but the size is 9, not 1.
Then I "GEP" from %7 which I treat it as a [1 x i32]*, not [9 x
i32]* , but the "offset" is 5(%6).
So, is there any problem? Not safe, or just not good but basically
OK?