Skip to content

Commit bd7847c

Browse files
committed
fix: get llvm type of global val
1 parent 9337f7a commit bd7847c

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

compiler/rustc_codegen_llvm/src/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl<'ll> CodegenCx<'ll, '_> {
390390
let val_llty = self.val_ty(v);
391391

392392
let g = self.get_static_inner(def_id, val_llty);
393-
let llty = self.val_ty(g);
393+
let llty = llvm::LLVMRustGetGlobalValType(g);
394394

395395
let g = if val_llty == llty {
396396
g

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ extern "C" {
974974
pub fn LLVMGetAlignment(Global: &Value) -> c_uint;
975975
pub fn LLVMSetAlignment(Global: &Value, Bytes: c_uint);
976976
pub fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass);
977+
pub fn LLVMRustGetGlobalValType(Global: &Value) -> &Type;
977978

978979
// Operations on global variables
979980
pub fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>;

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,11 @@ extern "C" void LLVMRustSetLinkage(LLVMValueRef V,
17411741
LLVMSetLinkage(V, fromRust(RustLinkage));
17421742
}
17431743

1744+
1745+
extern "C" LLVMTypeRef LLVMRustGetGlobalValType(LLVMValueRef Global) {
1746+
return wrap(unwrap<GlobalValue>(Global)->getValueType());
1747+
}
1748+
17441749
extern "C" bool LLVMRustConstIntGetZExtValue(LLVMValueRef CV, uint64_t *value) {
17451750
auto C = unwrap<llvm::ConstantInt>(CV);
17461751
if (C->getBitWidth() > 64)

0 commit comments

Comments
 (0)