Skip to content

Commit 92b231f

Browse files
committed
add aliasses to llvm
1 parent 8ce2287 commit 92b231f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,4 +2662,12 @@ unsafe extern "C" {
26622662

26632663
pub(crate) fn LLVMRustSetNoSanitizeAddress(Global: &Value);
26642664
pub(crate) fn LLVMRustSetNoSanitizeHWAddress(Global: &Value);
2665+
2666+
pub(crate) fn LLVMAddAlias2(
2667+
M: &Module,
2668+
ValueTy: &Type,
2669+
AddressSpace: c_uint,
2670+
Aliasee: &Value,
2671+
Name: *const c_char,
2672+
);
26652673
}

compiler/rustc_codegen_llvm/src/llvm/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::str::FromStr;
66
use std::string::FromUtf8Error;
77

88
use libc::c_uint;
9-
use rustc_abi::{Align, Size, WrappingRange};
9+
use rustc_abi::{AddressSpace, Align, Size, WrappingRange};
1010
use rustc_llvm::RustString;
1111

1212
pub(crate) use self::CallConv::*;
@@ -327,6 +327,20 @@ pub(crate) fn get_value_name(value: &Value) -> &[u8] {
327327
}
328328
}
329329

330+
/// Safe wrapper for `LLVMAddAlias2`
331+
pub(crate) fn add_alias(
332+
module: &Module,
333+
ty: &Type,
334+
address_space: AddressSpace,
335+
aliasee: &Value,
336+
name: &[u8],
337+
) {
338+
unsafe {
339+
let data = name.as_c_char_ptr();
340+
LLVMAddAlias2(value, data, address_space, aliasee, name.len());
341+
}
342+
}
343+
330344
/// Safe wrapper for `LLVMSetValueName2` from a byte slice
331345
pub(crate) fn set_value_name(value: &Value, name: &[u8]) {
332346
unsafe {

0 commit comments

Comments
 (0)