[llvm-commits] checking of inbounds for multi dimensional arrary and struct array on isInBoundsIndices()
Jin Gu Kang
jaykang10 at imrc.kist.re.kr
Wed Mar 2 21:00:23 PST 2011
Hi all
isBounsIndices() function decides to set inbounds flag and uses one-past-the-end
rule about index. I think one-past-the-end rule is applied to multi-dimensional
array and struct array.
What do you think about this?
I tested the following code.
char a[3][2];
struct test {
char a;
int b;
};
struct test foo[3];
int main(void) {
a[2][1] = 1;
a[3][0] = 2;
a[3][1] = 3;
a[3][2] = 4;
foo[2].a = 5;
foo[3].a = 6;
foo[3].b = 7;
}
------------------------------------------------------------------
define i32 @main() nounwind {
entry:
%retval = alloca i32
%"alloca point" = bitcast i32 0 to i32
store i8 1, i8* getelementptr inbounds ([3 x [2 x i8]]* @a, i32 0, i32 2, i32 1), align 1
store i8 2, i8* getelementptr inbounds ([3 x [2 x i8]]* @a, i32 1, i32 0, i32 0), align 1
store i8 3, i8* getelementptr ([3 x [2 x i8]]* @a, i32 1, i32 0, i32 1), align 1
store i8 4, i8* getelementptr ([3 x [2 x i8]]* @a, i32 1, i32 1, i32 0), align 1
store i8 5, i8* getelementptr inbounds ([3 x %struct.test]* @foo, i32 0, i32 2, i32 0), align 4
store i8 6, i8* getelementptr inbounds ([3 x %struct.test]* @foo, i32 1, i32 0, i32 0), align 4
store i32 7, i32* getelementptr ([3 x %struct.test]* @foo, i32 1, i32 0, i32 1), align 4
br label %return
return: ; preds = %entry
%retval1 = load i32* %retval
ret i32 %retval1
}
-------------------------------------------------------------------
isInBoundsIndices() doesn't return inbounds flag as true on
a[3][1] = 3, a[3][2] = 4 and foo[3].b = 7.
I made a patch to fix this.
This patch has a little "if-else" statements to process some of cases.
If you find a better solution, please let me know. :)
Please review the attached patch.
Thanks,
Jin-Gu Kang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110303/e6fe5ae1/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: inbounds.patch
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110303/e6fe5ae1/attachment.ksh>
More information about the llvm-commits
mailing list