Skip to content

Commit 07afdb8

Browse files
committed
Use bitcast for ptrtoint and inttoptr
This works now
1 parent b48ed38 commit 07afdb8

File tree

2 files changed

+5
-29
lines changed

2 files changed

+5
-29
lines changed

src/builder.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,11 +904,12 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
904904
}
905905

906906
fn ptrtoint(&mut self, value: RValue<'gcc>, dest_ty: Type<'gcc>) -> RValue<'gcc> {
907-
self.cx.ptrtoint(self.block, value, dest_ty)
907+
let usize_value = self.cx.const_bitcast(value, self.cx.type_isize());
908+
self.intcast(usize_value, dest_ty, false)
908909
}
909910

910911
fn inttoptr(&mut self, value: RValue<'gcc>, dest_ty: Type<'gcc>) -> RValue<'gcc> {
911-
self.cx.inttoptr(self.block, value, dest_ty)
912+
self.cx.const_bitcast(value, dest_ty)
912913
}
913914

914915
fn bitcast(&mut self, value: RValue<'gcc>, dest_ty: Type<'gcc>) -> RValue<'gcc> {

src/common.rs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use gccjit::LValue;
2-
use gccjit::{Block, RValue, Type, ToRValue};
2+
use gccjit::{RValue, Type, ToRValue};
33
use rustc_codegen_ssa::mir::place::PlaceRef;
44
use rustc_codegen_ssa::traits::{
55
BaseTypeMethods,
@@ -45,27 +45,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
4545
global
4646
// TODO(antoyo): set linkage.
4747
}
48-
49-
pub fn inttoptr(&self, block: Block<'gcc>, value: RValue<'gcc>, dest_ty: Type<'gcc>) -> RValue<'gcc> {
50-
let func = block.get_function();
51-
let local = func.new_local(None, value.get_type(), "intLocal");
52-
block.add_assignment(None, local, value);
53-
let value_address = local.get_address(None);
54-
55-
let ptr = self.context.new_cast(None, value_address, dest_ty.make_pointer());
56-
ptr.dereference(None).to_rvalue()
57-
}
58-
59-
pub fn ptrtoint(&self, block: Block<'gcc>, value: RValue<'gcc>, dest_ty: Type<'gcc>) -> RValue<'gcc> {
60-
// TODO(antoyo): when libgccjit allow casting from pointer to int, remove this.
61-
let func = block.get_function();
62-
let local = func.new_local(None, value.get_type(), "ptrLocal");
63-
block.add_assignment(None, local, value);
64-
let ptr_address = local.get_address(None);
65-
66-
let ptr = self.context.new_cast(None, ptr_address, dest_ty.make_pointer());
67-
ptr.dereference(None).to_rvalue()
68-
}
6948
}
7049

7150
pub fn bytes_in_context<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, bytes: &[u8]) -> RValue<'gcc> {
@@ -202,11 +181,7 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
202181
}
203182

204183
let value = self.const_uint_big(self.type_ix(bitsize), data);
205-
if layout.value == Pointer {
206-
self.inttoptr(self.current_block.borrow().expect("block"), value, ty)
207-
} else {
208-
self.const_bitcast(value, ty)
209-
}
184+
self.const_bitcast(value, ty)
210185
}
211186
Scalar::Ptr(ptr, _size) => {
212187
let (alloc_id, offset) = ptr.into_parts();

0 commit comments

Comments
 (0)