Skip to content

Commit 908304e

Browse files
committed
Rewrite inbounds_gep with a loop
1 parent 090cde9 commit 908304e

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
@@ -876,17 +876,13 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
876876

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

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

0 commit comments

Comments
 (0)