Skip to content

Commit

Permalink
codegen: on old LLVM, avoid 'inbounds'
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Oct 28, 2023
1 parent e354eab commit f481ef0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
33 changes: 24 additions & 9 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,15 +715,30 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
ptr: &'ll Value,
indices: &[&'ll Value],
) -> &'ll Value {
unsafe {
llvm::LLVMBuildInBoundsGEP2(
self.llbuilder,
ty,
ptr,
indices.as_ptr(),
indices.len() as c_uint,
UNNAMED,
)
let llvm_version = llvm_util::get_version();
if llvm_version < (17, 0, 0) {
// Old LLVM does not yet have https://reviews.llvm.org/D154051, so we cannot add `inbounds`.
unsafe {
llvm::LLVMBuildGEP2(
self.llbuilder,
ty,
ptr,
indices.as_ptr(),
indices.len() as c_uint,
UNNAMED,
)
}
} else {
unsafe {
llvm::LLVMBuildInBoundsGEP2(
self.llbuilder,
ty,
ptr,
indices.as_ptr(),
indices.len() as c_uint,
UNNAMED,
)
}
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/codegen/intrinsics/offset.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// compile-flags: -O -C no-prepopulate-passes
// min-llvm-version: 17

#![crate_type = "lib"]
#![feature(core_intrinsics)]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/repeat-trusted-len.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// compile-flags: -O
//
// min-llvm-version: 17

#![crate_type = "lib"]

Expand Down
1 change: 1 addition & 0 deletions tests/codegen/vec_pop_push_noop.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// compile-flags: -O
// min-llvm-version: 17

#![crate_type = "lib"]

Expand Down

0 comments on commit f481ef0

Please sign in to comment.