Fix gep on pointers to non-number

This commit is contained in:
Antoni Boucher 2023-09-19 22:20:35 -04:00
parent f3b82df8f8
commit be3b1e3321
7 changed files with 31 additions and 8 deletions

4
Cargo.lock generated
View File

@ -74,7 +74,7 @@ dependencies = [
[[package]] [[package]]
name = "gccjit" name = "gccjit"
version = "1.0.0" version = "1.0.0"
source = "git+https://github.com/antoyo/gccjit.rs#ff1f82584c760a8b870dc6bad9841bd090f92f80" source = "git+https://github.com/antoyo/gccjit.rs#0b158c68bf7e46732869d90550a98e886dee8858"
dependencies = [ dependencies = [
"gccjit_sys", "gccjit_sys",
] ]
@ -82,7 +82,7 @@ dependencies = [
[[package]] [[package]]
name = "gccjit_sys" name = "gccjit_sys"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/antoyo/gccjit.rs#ff1f82584c760a8b870dc6bad9841bd090f92f80" source = "git+https://github.com/antoyo/gccjit.rs#0b158c68bf7e46732869d90550a98e886dee8858"
dependencies = [ dependencies = [
"libc", "libc",
] ]

View File

@ -14,7 +14,6 @@ tests/ui/sepcomp/sepcomp-fns-backwards.rs
tests/ui/sepcomp/sepcomp-fns.rs tests/ui/sepcomp/sepcomp-fns.rs
tests/ui/sepcomp/sepcomp-statics.rs tests/ui/sepcomp/sepcomp-statics.rs
tests/ui/simd/intrinsic/generic-arithmetic-pass.rs tests/ui/simd/intrinsic/generic-arithmetic-pass.rs
tests/ui/target-feature/missing-plusminus.rs
tests/ui/asm/x86_64/may_unwind.rs tests/ui/asm/x86_64/may_unwind.rs
tests/ui/backtrace.rs tests/ui/backtrace.rs
tests/ui/catch-unwind-bang.rs tests/ui/catch-unwind-bang.rs

View File

@ -37,3 +37,4 @@ tests/ui/simd/intrinsic/generic-gather-pass.rs
tests/ui/simd/issue-85915-simd-ptrs.rs tests/ui/simd/issue-85915-simd-ptrs.rs
tests/ui/issues/issue-68010-large-zst-consts.rs tests/ui/issues/issue-68010-large-zst-consts.rs
tests/ui/rust-2018/proc-macro-crate-in-paths.rs tests/ui/rust-2018/proc-macro-crate-in-paths.rs
tests/ui/target-feature/missing-plusminus.rs

View File

@ -922,6 +922,12 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
// require dereferencing the pointer. // require dereferencing the pointer.
for index in indices { for index in indices {
pointee_type = pointee_type.get_pointee().expect("pointee type"); pointee_type = pointee_type.get_pointee().expect("pointee type");
#[cfg(feature="master")]
let pointee_size = {
let size = self.cx.context.new_sizeof(pointee_type);
self.context.new_cast(None, size, index.get_type())
};
#[cfg(not(feature="master"))]
let pointee_size = self.context.new_rvalue_from_int(index.get_type(), pointee_type.get_size() as i32); let pointee_size = self.context.new_rvalue_from_int(index.get_type(), pointee_type.get_size() as i32);
result = result + self.gcc_int_cast(*index * pointee_size, self.sizet_type); result = result + self.gcc_int_cast(*index * pointee_size, self.sizet_type);
} }

View File

@ -1,3 +1,4 @@
#[cfg(feature="master")]
use gccjit::Context; use gccjit::Context;
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
@ -202,11 +203,16 @@ fn handle_native(name: &str) -> &str {
return name; return name;
} }
// Get the native arch. #[cfg(feature="master")]
let context = Context::default(); {
context.get_target_info().arch().unwrap() // Get the native arch.
.to_str() let context = Context::default();
.unwrap() context.get_target_info().arch().unwrap()
.to_str()
.unwrap()
}
#[cfg(not(feature="master"))]
unimplemented!();
} }
pub fn target_cpu(sess: &Session) -> &str { pub fn target_cpu(sess: &Session) -> &str {

View File

@ -220,6 +220,7 @@ changelog-seen = 2
[rust] [rust]
codegen-backends = [] codegen-backends = []
deny-warnings = false deny-warnings = false
verbose-tests = true
[build] [build]
cargo = "$(rustup which cargo)" cargo = "$(rustup which cargo)"

10
tests/run/gep.rs Normal file
View File

@ -0,0 +1,10 @@
// Compiler:
//
// Run-time:
// status: 0
fn main() {
let mut value = (1, 1);
let ptr = &mut value as *mut (i32, i32);
println!("{:?}", ptr.wrapping_offset(10));
}