Skip to content

Commit 4b92156

Browse files
committed
Rewrite inbounds_gep with a loop
1 parent 169a11b commit 4b92156

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/builder.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -873,17 +873,13 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
873873

874874
fn inbounds_gep(&mut self, _typ: Type<'gcc>, ptr: RValue<'gcc>, indices: &[RValue<'gcc>]) -> RValue<'gcc> {
875875
// NOTE: array indexing is always considered in bounds in GCC (TODO(antoyo): to be verified).
876-
// TODO: replace with a loop like gep.
877-
match indices.len() {
878-
1 => {
879-
self.context.new_array_access(None, ptr, indices[0]).get_address(None)
880-
},
881-
2 => {
882-
let array = ptr.dereference(None); // TODO(antoyo): assert that first index is 0?
883-
self.context.new_array_access(None, array, indices[1]).get_address(None)
884-
},
885-
_ => unimplemented!(),
876+
let mut indices = indices.into_iter();
877+
let index = indices.next().expect("first index in inbounds_gep");
878+
let mut result = self.context.new_array_access(None, ptr, *index);
879+
for index in indices {
880+
result = self.context.new_array_access(None, result, *index);
886881
}
882+
result.get_address(None)
887883
}
888884

889885
fn struct_gep(&mut self, value_type: Type<'gcc>, ptr: RValue<'gcc>, idx: u64) -> RValue<'gcc> {

0 commit comments

Comments
 (0)