@@ -102,3 +102,74 @@ void test_cleanup_zero_length_array() {
102
102
// OGCG: alloca [0 x %struct.S]
103
103
// OGCG-NOT: call void @_ZN1SD1Ev
104
104
// OGCG: ret void
105
+
106
+ void multi_dimensional () {
107
+ S s[3 ][5 ];
108
+ }
109
+
110
+ // CIR-BEFORE-LPP: cir.func{{.*}} @_Z17multi_dimensionalv()
111
+ // CIR-BEFORE-LPP: %[[S:.*]] = cir.alloca !cir.array<!cir.array<!rec_S x 5> x 3>, !cir.ptr<!cir.array<!cir.array<!rec_S x 5> x 3>>, ["s"]
112
+ // CIR-BEFORE-LPP: %[[FLAT:.*]] = cir.cast(bitcast, %[[S]] : !cir.ptr<!cir.array<!cir.array<!rec_S x 5> x 3>>), !cir.ptr<!cir.array<!rec_S x 15>>
113
+ // CIR-BEFORE-LPP: cir.array.dtor %[[FLAT]] : !cir.ptr<!cir.array<!rec_S x 15>> {
114
+ // CIR-BEFORE-LPP: ^bb0(%[[ARG:.*]]: !cir.ptr<!rec_S>):
115
+ // CIR-BEFORE-LPP: cir.call @_ZN1SD1Ev(%[[ARG]]) nothrow : (!cir.ptr<!rec_S>) -> ()
116
+ // CIR-BEFORE-LPP: cir.yield
117
+ // CIR-BEFORE-LPP: }
118
+ // CIR-BEFORE-LPP: cir.return
119
+
120
+ // CIR: cir.func{{.*}} @_Z17multi_dimensionalv()
121
+ // CIR: %[[S:.*]] = cir.alloca !cir.array<!cir.array<!rec_S x 5> x 3>, !cir.ptr<!cir.array<!cir.array<!rec_S x 5> x 3>>, ["s"]
122
+ // CIR: %[[FLAT:.*]] = cir.cast(bitcast, %[[S]] : !cir.ptr<!cir.array<!cir.array<!rec_S x 5> x 3>>), !cir.ptr<!cir.array<!rec_S x 15>>
123
+ // CIR: %[[CONST14:.*]] = cir.const #cir.int<14> : !u64i
124
+ // CIR: %[[DECAY:.*]] = cir.cast(array_to_ptrdecay, %[[FLAT]] : !cir.ptr<!cir.array<!rec_S x 15>>), !cir.ptr<!rec_S>
125
+ // CIR: %[[END_PTR:.*]] = cir.ptr_stride(%[[DECAY]] : !cir.ptr<!rec_S>, %[[CONST14]] : !u64i), !cir.ptr<!rec_S>
126
+ // CIR: %[[ITER:.*]] = cir.alloca !cir.ptr<!rec_S>, !cir.ptr<!cir.ptr<!rec_S>>, ["__array_idx"]
127
+ // CIR: cir.store %[[END_PTR]], %[[ITER]] : !cir.ptr<!rec_S>, !cir.ptr<!cir.ptr<!rec_S>>
128
+ // CIR: cir.do {
129
+ // CIR: %[[CUR:.*]] = cir.load %[[ITER]] : !cir.ptr<!cir.ptr<!rec_S>>, !cir.ptr<!rec_S>
130
+ // CIR: cir.call @_ZN1SD1Ev(%[[CUR]]) nothrow : (!cir.ptr<!rec_S>) -> ()
131
+ // CIR: %[[NEG1:.*]] = cir.const #cir.int<-1> : !s64i
132
+ // CIR: %[[PREV:.*]] = cir.ptr_stride(%[[CUR]] : !cir.ptr<!rec_S>, %[[NEG1]] : !s64i), !cir.ptr<!rec_S>
133
+ // CIR: cir.store %[[PREV]], %[[ITER]] : !cir.ptr<!rec_S>, !cir.ptr<!cir.ptr<!rec_S>>
134
+ // CIR: cir.yield
135
+ // CIR: } while {
136
+ // CIR: %[[CHK:.*]] = cir.load %[[ITER]] : !cir.ptr<!cir.ptr<!rec_S>>, !cir.ptr<!rec_S>
137
+ // CIR: %[[CMP:.*]] = cir.cmp(ne, %[[CHK]], %[[DECAY]])
138
+ // CIR: cir.condition(%[[CMP]])
139
+ // CIR: }
140
+ // CIR: cir.return
141
+
142
+ // LLVM: define{{.*}} void @_Z17multi_dimensionalv()
143
+ // LLVM: %[[S:.*]] = alloca [3 x [5 x %struct.S]]
144
+ // LLVM: %[[START:.*]] = getelementptr %struct.S, ptr %[[S]], i32 0
145
+ // LLVM: %[[END:.*]] = getelementptr %struct.S, ptr %[[START]], i64 14
146
+ // LLVM: %[[ITER:.*]] = alloca ptr
147
+ // LLVM: store ptr %[[END]], ptr %[[ITER]]
148
+ // LLVM: br label %[[LOOP:.*]]
149
+ // LLVM: [[COND:.*]]:
150
+ // LLVM: %[[CURRENT_CHECK:.*]] = load ptr, ptr %[[ITER]]
151
+ // LLVM: %[[DONE:.*]] = icmp ne ptr %[[CURRENT_CHECK]], %[[START]]
152
+ // LLVM: br i1 %[[DONE]], label %[[LOOP]], label %[[EXIT:.*]]
153
+ // LLVM: [[LOOP]]:
154
+ // LLVM: %[[CUR:.*]] = load ptr, ptr %[[ITER]]
155
+ // LLVM: call void @_ZN1SD1Ev(ptr %[[CUR]])
156
+ // LLVM: %[[PREV:.*]] = getelementptr %struct.S, ptr %[[CUR]], i64 -1
157
+ // LLVM: store ptr %[[PREV]], ptr %[[ITER]]
158
+ // LLVM: br label %[[COND]]
159
+ // LLVM: [[EXIT]]:
160
+ // LLVM: ret void
161
+
162
+ // OGCG: define{{.*}} void @_Z17multi_dimensionalv()
163
+ // OGCG: %[[ARRAY:.*]] = alloca [3 x [5 x %struct.S]]
164
+ // OGCG: %[[START:.*]] = getelementptr{{.*}} %struct.S{{.*}}
165
+ // OGCG: %[[END:.*]] = getelementptr{{.*}} %struct.S{{.*}} i64 15
166
+ // OGCG: br label %[[LOOP:.*]]
167
+ // OGCG: [[LOOP]]:
168
+ // OGCG: %[[NEXT:.*]] = phi ptr [ %[[END]], %{{.*}} ], [ %[[LAST:.*]], %[[LOOP]] ]
169
+ // OGCG: %[[LAST]] = getelementptr{{.*}} %struct.S{{.*}}, ptr %[[NEXT]], i64 -1
170
+ // OGCG: call void @_ZN1SD1Ev(ptr{{.*}} %[[LAST]])
171
+ // OGCG: %[[DONE:.*]] = icmp eq ptr %[[LAST]], %[[START]]
172
+ // OGCG: br i1 %[[DONE]], label %[[EXIT:.*]], label %[[LOOP]]
173
+ // OGCG: [[EXIT]]:
174
+ // OGCG: ret void
175
+
0 commit comments