Skip to content

Commit 8e0df32

Browse files
committed
Replace LLVMConstInBoundsGEP with LLVMConstInBoundsGEP2*
A custom reimplementation of LLVMConstInBoundsGEP2 is used, since the LLVM contains a declaration of LLVMConstInBoundsGEP2 but not the implementation.
1 parent 77e5e17 commit 8e0df32

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

compiler/rustc_codegen_llvm/src/common.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
268268
}
269269
};
270270
let llval = unsafe {
271-
llvm::LLVMConstInBoundsGEP(
271+
llvm::LLVMRustConstInBoundsGEP2(
272+
self.type_i8(),
272273
self.const_bitcast(base_addr, self.type_i8p_ext(base_addr_space)),
273274
&self.const_usize(offset.bytes()),
274275
1,
@@ -303,7 +304,8 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
303304
let base_addr = self.static_addr_of(init, alloc.align, None);
304305

305306
let llval = unsafe {
306-
llvm::LLVMConstInBoundsGEP(
307+
llvm::LLVMRustConstInBoundsGEP2(
308+
self.type_i8(),
307309
self.const_bitcast(base_addr, self.type_i8p()),
308310
&self.const_usize(offset.bytes()),
309311
1,

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,8 @@ extern "C" {
10111011
pub fn LLVMConstVector(ScalarConstantVals: *const &Value, Size: c_uint) -> &Value;
10121012

10131013
// Constant expressions
1014-
pub fn LLVMConstInBoundsGEP(
1014+
pub fn LLVMRustConstInBoundsGEP2(
1015+
ty: &'a Type,
10151016
ConstantVal: &'a Value,
10161017
ConstantIndices: *const &'a Value,
10171018
NumIndices: c_uint,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -1551,6 +1551,16 @@ extern "C" void LLVMRustSetLinkage(LLVMValueRef V,
15511551
LLVMSetLinkage(V, fromRust(RustLinkage));
15521552
}
15531553

1554+
extern "C" LLVMValueRef LLVMRustConstInBoundsGEP2(LLVMTypeRef Ty,
1555+
LLVMValueRef ConstantVal,
1556+
LLVMValueRef *ConstantIndices,
1557+
unsigned NumIndices) {
1558+
ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
1559+
NumIndices);
1560+
Constant *Val = unwrap<Constant>(ConstantVal);
1561+
return wrap(ConstantExpr::getInBoundsGetElementPtr(unwrap(Ty), Val, IdxList));
1562+
}
1563+
15541564
// Returns true if both high and low were successfully set. Fails in case constant wasn’t any of
15551565
// the common sizes (1, 8, 16, 32, 64, 128 bits)
15561566
extern "C" bool LLVMRustConstInt128Get(LLVMValueRef CV, bool sext, uint64_t *high, uint64_t *low)

0 commit comments

Comments
 (0)