Merge pull request #337 from rust-lang/fix/gep

Fix gep on pointers to non-number
This commit is contained in:
antoyo 2023-09-20 17:57:04 -04:00 committed by GitHub
commit e7d1dc33c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 8 deletions

4
Cargo.lock generated
View File

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

View File

@ -14,7 +14,6 @@ tests/ui/sepcomp/sepcomp-fns-backwards.rs
tests/ui/sepcomp/sepcomp-fns.rs
tests/ui/sepcomp/sepcomp-statics.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/backtrace.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/issues/issue-68010-large-zst-consts.rs
tests/ui/rust-2018/proc-macro-crate-in-paths.rs
tests/ui/target-feature/missing-plusminus.rs

View File

@ -922,6 +922,12 @@ fn gep(&mut self, typ: Type<'gcc>, ptr: RValue<'gcc>, indices: &[RValue<'gcc>])
// require dereferencing the pointer.
for index in indices {
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);
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 smallvec::{smallvec, SmallVec};
@ -202,11 +203,16 @@ fn handle_native(name: &str) -> &str {
return name;
}
// Get the native arch.
let context = Context::default();
context.get_target_info().arch().unwrap()
.to_str()
.unwrap()
#[cfg(feature="master")]
{
// Get the native arch.
let context = Context::default();
context.get_target_info().arch().unwrap()
.to_str()
.unwrap()
}
#[cfg(not(feature="master"))]
unimplemented!();
}
pub fn target_cpu(sess: &Session) -> &str {

View File

@ -220,6 +220,7 @@ changelog-seen = 2
[rust]
codegen-backends = []
deny-warnings = false
verbose-tests = true
[build]
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));
}