Skip to content

Commit 7560748

Browse files
committed
codegen: on old LLVM, avoid 'inbounds'
1 parent e354eab commit 7560748

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

+24-9
Original file line numberDiff line numberDiff line change
@@ -715,15 +715,30 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
715715
ptr: &'ll Value,
716716
indices: &[&'ll Value],
717717
) -> &'ll Value {
718-
unsafe {
719-
llvm::LLVMBuildInBoundsGEP2(
720-
self.llbuilder,
721-
ty,
722-
ptr,
723-
indices.as_ptr(),
724-
indices.len() as c_uint,
725-
UNNAMED,
726-
)
718+
let llvm_version = llvm_util::get_version();
719+
if llvm_version < (17, 0, 0) {
720+
// Old LLVM does not yet have https://reviews.llvm.org/D154051, so we cannot add `inbounds`.
721+
unsafe {
722+
llvm::LLVMBuildGEP2(
723+
self.llbuilder,
724+
ty,
725+
ptr,
726+
indices.as_ptr(),
727+
indices.len() as c_uint,
728+
UNNAMED,
729+
)
730+
}
731+
} else {
732+
unsafe {
733+
llvm::LLVMBuildInBoundsGEP2(
734+
self.llbuilder,
735+
ty,
736+
ptr,
737+
indices.as_ptr(),
738+
indices.len() as c_uint,
739+
UNNAMED,
740+
)
741+
}
727742
}
728743
}
729744

0 commit comments

Comments
 (0)