Skip to content

Commit a3a88c7

Browse files
committed
llvm-wrapper: adapt for LLVMConstExtractValue removal
1 parent a9eb9c5 commit a3a88c7

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

compiler/rustc_codegen_llvm/src/common.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ impl<'ll> CodegenCx<'ll, '_> {
109109
pub fn const_get_elt(&self, v: &'ll Value, idx: u64) -> &'ll Value {
110110
unsafe {
111111
assert_eq!(idx as c_uint as u64, idx);
112-
let us = &[idx as c_uint];
113-
let r = llvm::LLVMConstExtractValue(v, us.as_ptr(), us.len() as c_uint);
112+
let r = llvm::LLVMGetAggregateElement(v, idx as c_uint).unwrap();
114113

115114
debug!("const_get_elt(v={:?}, idx={}, r={:?})", v, idx, r);
116115

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1134,11 +1134,7 @@ extern "C" {
11341134
pub fn LLVMConstIntToPtr<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
11351135
pub fn LLVMConstBitCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
11361136
pub fn LLVMConstPointerCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1137-
pub fn LLVMConstExtractValue(
1138-
AggConstant: &Value,
1139-
IdxList: *const c_uint,
1140-
NumIdx: c_uint,
1141-
) -> &Value;
1137+
pub fn LLVMGetAggregateElement(ConstantVal: &Value, Idx: c_uint) -> Option<&Value>;
11421138

11431139
// Operations on global variables, functions, and aliases (globals)
11441140
pub fn LLVMIsDeclaration(Global: &Value) -> Bool;

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1865,3 +1865,11 @@ extern "C" void LLVMRustGetMangledName(LLVMValueRef V, RustStringRef Str) {
18651865
GlobalValue *GV = unwrap<GlobalValue>(V);
18661866
Mangler().getNameWithPrefix(OS, GV, true);
18671867
}
1868+
1869+
// LLVMGetAggregateElement was added in LLVM 15. For earlier LLVM versions just
1870+
// use its implementation.
1871+
#if LLVM_VERSION_LT(15, 0)
1872+
extern "C" LLVMValueRef LLVMGetAggregateElement(LLVMValueRef C, unsigned Idx) {
1873+
return wrap(unwrap<Constant>(C)->getAggregateElement(Idx));
1874+
}
1875+
#endif

0 commit comments

Comments
 (0)