llvm.org GIT mirror llvm / 2c91d10
Fix a bug in ComputeLinearIndex computation handling multi-level aggregate types. Don't increment the current index after reaching the end of a struct, as it will already be pointing at one-past-the end. This fixes PR3288. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61828 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 11 years ago
2 changed file(s) with 70 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
6262 cl::init(0));
6363
6464 /// ComputeLinearIndex - Given an LLVM IR aggregate type and a sequence
65 /// insertvalue or extractvalue indices that identify a member, return
65 /// of insertvalue or extractvalue indices that identify a member, return
6666 /// the linearized index of the start of the member.
6767 ///
6868 static unsigned ComputeLinearIndex(const TargetLowering &TLI, const Type *Ty,
8383 return ComputeLinearIndex(TLI, *EI, Indices+1, IndicesEnd, CurIndex);
8484 CurIndex = ComputeLinearIndex(TLI, *EI, 0, 0, CurIndex);
8585 }
86 return CurIndex;
8687 }
8788 // Given an array type, recursively traverse the elements.
8889 else if (const ArrayType *ATy = dyn_cast(Ty)) {
9293 return ComputeLinearIndex(TLI, EltTy, Indices+1, IndicesEnd, CurIndex);
9394 CurIndex = ComputeLinearIndex(TLI, EltTy, 0, 0, CurIndex);
9495 }
96 return CurIndex;
9597 }
9698 // We haven't found the type we're looking for, so keep searching.
9799 return CurIndex + 1;
0 ; RUN: llvm-as < %s | llc
1 ; PR3288
2
3 define void @a() {
4 %i = insertvalue [2 x [2 x i32]] undef, [2 x i32] undef, 1
5 ret void
6 }
7 define void @b() {
8 %i = insertvalue {{i32,float},{i16,double}} undef, {i16,double} undef, 1
9 ret void
10 }
11 define void @c() {
12 %i = insertvalue [2 x [2 x i32]] zeroinitializer, [2 x i32] zeroinitializer, 1
13 ret void
14 }
15 define void @d() {
16 %i = insertvalue {{i32,float},{i16,double}} zeroinitializer, {i16,double} zeroinitializer, 1
17 ret void
18 }
19 define void @e() {
20 %i = insertvalue [2 x [2 x i32]] undef, [2 x i32] undef, 0
21 ret void
22 }
23 define void @f() {
24 %i = insertvalue {{i32,float},{i16,double}} undef, {i32,float} undef, 0
25 ret void
26 }
27 define void @g() {
28 %i = insertvalue [2 x [2 x i32]] zeroinitializer, [2 x i32] zeroinitializer, 0
29 ret void
30 }
31 define void @h() {
32 %i = insertvalue {{i32,float},{i16,double}} zeroinitializer, {i32,float} zeroinitializer, 0
33 ret void
34 }
35 define void @ax() {
36 %i = insertvalue [2 x [2 x i32]] undef, i32 undef, 1, 1
37 ret void
38 }
39 define void @bx() {
40 %i = insertvalue {{i32,float},{i16,double}} undef, double undef, 1, 1
41 ret void
42 }
43 define void @cx() {
44 %i = insertvalue [2 x [2 x i32]] zeroinitializer, i32 zeroinitializer, 1, 1
45 ret void
46 }
47 define void @dx() {
48 %i = insertvalue {{i32,float},{i16,double}} zeroinitializer, double zeroinitializer, 1, 1
49 ret void
50 }
51 define void @ex() {
52 %i = insertvalue [2 x [2 x i32]] undef, i32 undef, 0, 1
53 ret void
54 }
55 define void @fx() {
56 %i = insertvalue {{i32,float},{i16,double}} undef, float undef, 0, 1
57 ret void
58 }
59 define void @gx() {
60 %i = insertvalue [2 x [2 x i32]] zeroinitializer, i32 zeroinitializer, 0, 1
61 ret void
62 }
63 define void @hx() {
64 %i = insertvalue {{i32,float},{i16,double}} zeroinitializer, float zeroinitializer, 0, 1
65 ret void
66 }