Skip to content

Commit

Permalink
Merge pull request rust-lang#337 from rust-lang/fix/gep
Browse files Browse the repository at this point in the history
Fix gep on pointers to non-number
  • Loading branch information
antoyo authored Sep 20, 2023
2 parents 6118ee4 + be3b1e3 commit e7d1dc3
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion failing-ui-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions failing-ui-tests12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,12 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
// 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);
}
Expand Down
16 changes: 11 additions & 5 deletions src/gcc_util.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature="master")]
use gccjit::Context;
use smallvec::{smallvec, SmallVec};

Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ changelog-seen = 2
[rust]
codegen-backends = []
deny-warnings = false
verbose-tests = true
[build]
cargo = "$(rustup which cargo)"
Expand Down
10 changes: 10 additions & 0 deletions tests/run/gep.rs
Original file line number Diff line number Diff line change
@@ -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));
}

0 comments on commit e7d1dc3

Please sign in to comment.