<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=GB2312">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi, all<br>
I am trying to use GEP to get a pointer of i32 from an array.<br>
But the problem is: I don't know the size of the array.<br>
The IR document on llvm.org said GEP just adds the offsets to the
base address with silently-wrapping two¡¯s complement arithmetic.<br>
So, I want to ask for some advice.<br>
Is it safe like this:<br>
<font color="#3366ff"><br>
%v1 = alloca i32
<br>
store i32 5, i32* %v1
<br>
%6 = load i32* %v1
<br>
%7 = bitcast i32* %v0 to [1 x i32]*
<br>
%8 = getelementptr [1 x i32]* %7, i32 0, i32 %6
<br>
%9 = load i32* %8
<br>
store i32 %9, i32* %v0</font><br>
<br>
Type of %v0 is i32*, and I know %v0 is pointing to an array in mem,
but the size is 9, not 1.<br>
Then I "GEP" from %7 which I treat it as a [1 x i32]*, not [9 x
i32]* , but the "offset" is 5(%6).<br>
<br>
So, is there any problem? Not safe, or just not good but basically
OK?<br>
</body>
</html>