Skip to content

Commit 735940d

Browse files
authored
Merge pull request #26 from antoyo/fix/pointer-offset
Fix exactsdiv
2 parents 74ea32d + db04470 commit 735940d

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

gcc-test-backend/src/main.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
fn main() {
2-
const OPTION: Option<usize> = Some(32);
3-
4-
const REF: Option<&usize> = OPTION.as_ref();
5-
assert_eq!(REF, Some(&32));
6-
7-
const IS_SOME: bool = OPTION.is_some();
8-
assert!(IS_SOME);
9-
10-
const IS_NONE: bool = OPTION.is_none();
11-
assert!(!IS_NONE);
2+
let mut a = [0; 5];
3+
let ptr1: *mut i32 = &mut a[1];
4+
let ptr2: *mut i32 = &mut a[3];
5+
unsafe {
6+
assert_eq!(ptr2.offset_from(ptr1), 2);
7+
assert_eq!(ptr1.offset_from(ptr2), -2);
8+
assert_eq!(ptr1.offset(2), ptr2);
9+
assert_eq!(ptr2.offset(-2), ptr1);
10+
}
1211
}

src/builder.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,23 +580,28 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
580580
}
581581

582582
fn udiv(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
583+
// TODO: convert the arguments to unsigned?
583584
a / b
584585
}
585586

586587
fn exactudiv(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
588+
// TODO: convert the arguments to unsigned?
587589
// TODO: poison if not exact.
588590
a / b
589591
}
590592

591593
fn sdiv(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
594+
// TODO: convert the arguments to signed?
592595
a / b
593596
}
594597

595598
fn exactsdiv(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
596599
// TODO: posion if not exact.
597600
// FIXME: rustc_codegen_ssa::mir::intrinsic uses different types for a and b but they
598601
// should be the same.
599-
let a = self.context.new_cast(None, a, b.get_type());
602+
let typ = a.get_type().to_signed(self);
603+
let a = self.context.new_cast(None, a, typ);
604+
let b = self.context.new_cast(None, b, typ);
600605
a / b
601606
}
602607

0 commit comments

Comments
 (0)