Skip to content

Commit 24dc2cb

Browse files
committed
librustc_codegen_llvm: Replace deprecated API usage
1 parent c20d7ee commit 24dc2cb

File tree

8 files changed

+23
-16
lines changed

8 files changed

+23
-16
lines changed

src/librustc_codegen_llvm/base.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ pub fn write_compressed_metadata<'tcx>(
7171
// flags, at least for ELF outputs, so that the
7272
// metadata doesn't get loaded into memory.
7373
let directive = format!(".section {}", section_name);
74-
let directive = CString::new(directive).unwrap();
75-
llvm::LLVMSetModuleInlineAsm(metadata_llmod, directive.as_ptr())
74+
llvm::LLVMSetModuleInlineAsm2(metadata_llmod, directive.as_ptr().cast(), directive.len())
7675
}
7776
}
7877

src/librustc_codegen_llvm/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::base;
22
use crate::common::CodegenCx;
33
use crate::debuginfo;
4-
use crate::llvm::{self, SetUnnamedAddr, True};
4+
use crate::llvm::{self, True};
55
use crate::type_::Type;
66
use crate::type_of::LayoutLlvmExt;
77
use crate::value::Value;
@@ -183,7 +183,7 @@ impl CodegenCx<'ll, 'tcx> {
183183
};
184184
llvm::LLVMSetInitializer(gv, cv);
185185
set_global_alignment(&self, gv, align);
186-
SetUnnamedAddr(gv, true);
186+
llvm::SetUnnamedAddress(gv, llvm::UnnamedAddr::Global);
187187
gv
188188
}
189189
}

src/librustc_codegen_llvm/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub unsafe fn create_module(
172172
llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm);
173173
llvm::LLVMRustDisposeTargetMachine(tm);
174174

175-
let llvm_data_layout = llvm::LLVMGetDataLayout(llmod);
175+
let llvm_data_layout = llvm::LLVMGetDataLayoutStr(llmod);
176176
let llvm_data_layout = str::from_utf8(CStr::from_ptr(llvm_data_layout).to_bytes())
177177
.expect("got a non-UTF8 data-layout from LLVM");
178178

@@ -504,7 +504,7 @@ impl CodegenCx<'b, 'tcx> {
504504
self.type_variadic_func(&[], ret)
505505
};
506506
let f = self.declare_cfn(name, fn_ty);
507-
llvm::SetUnnamedAddr(f, false);
507+
llvm::SetUnnamedAddress(f, llvm::UnnamedAddr::No);
508508
self.intrinsics.borrow_mut().insert(name, f);
509509
f
510510
}

src/librustc_codegen_llvm/debuginfo/gdb.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn get_or_insert_gdb_debug_scripts_section_global(cx: &CodegenCx<'ll, '_>) -
5050
llvm::LLVMSetSection(section_var, section_name.as_ptr().cast());
5151
llvm::LLVMSetInitializer(section_var, cx.const_bytes(section_contents));
5252
llvm::LLVMSetGlobalConstant(section_var, llvm::True);
53-
llvm::LLVMSetUnnamedAddr(section_var, llvm::True);
53+
llvm::LLVMSetUnnamedAddress(section_var, llvm::UnnamedAddr::Global);
5454
llvm::LLVMRustSetLinkage(section_var, llvm::Linkage::LinkOnceODRLinkage);
5555
// This should make sure that the whole section is not larger than
5656
// the string it contains. Otherwise we get a warning from GDB.

src/librustc_codegen_llvm/declare.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn declare_raw_fn(
4040
llvm::SetFunctionCallConv(llfn, callconv);
4141
// Function addresses in Rust are never significant, allowing functions to
4242
// be merged.
43-
llvm::SetUnnamedAddr(llfn, true);
43+
llvm::SetUnnamedAddress(llfn, llvm::UnnamedAddr::Global);
4444

4545
if cx.tcx.sess.opts.cg.no_redzone.unwrap_or(cx.tcx.sess.target.target.options.disable_redzone) {
4646
llvm::Attribute::NoRedZone.apply_llfn(Function, llfn);

src/librustc_codegen_llvm/intrinsic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ fn generic_simd_intrinsic(
16641664
llvm_elem_vec_ty,
16651665
),
16661666
);
1667-
llvm::SetUnnamedAddr(f, false);
1667+
llvm::SetUnnamedAddress(f, llvm::UnnamedAddr::No);
16681668
let v = bx.call(f, &[args[1].immediate(), alignment, mask, args[0].immediate()], None);
16691669
return Ok(v);
16701670
}
@@ -1786,7 +1786,7 @@ fn generic_simd_intrinsic(
17861786
&llvm_intrinsic,
17871787
bx.type_func(&[llvm_elem_vec_ty, llvm_pointer_vec_ty, alignment_ty, mask_ty], ret_t),
17881788
);
1789-
llvm::SetUnnamedAddr(f, false);
1789+
llvm::SetUnnamedAddress(f, llvm::UnnamedAddr::No);
17901790
let v = bx.call(f, &[args[0].immediate(), args[1].immediate(), alignment, mask], None);
17911791
return Ok(v);
17921792
}
@@ -2085,7 +2085,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
20852085
let vec_ty = bx.cx.type_vector(elem_ty, in_len as u64);
20862086

20872087
let f = bx.declare_cfn(&llvm_intrinsic, bx.type_func(&[vec_ty, vec_ty], vec_ty));
2088-
llvm::SetUnnamedAddr(f, false);
2088+
llvm::SetUnnamedAddress(f, llvm::UnnamedAddr::No);
20892089
let v = bx.call(f, &[lhs, rhs], None);
20902090
return Ok(v);
20912091
}

src/librustc_codegen_llvm/llvm/ffi.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ pub enum Visibility {
7373
Protected = 2,
7474
}
7575

76+
/// LLVMUnnamedAddr
77+
#[repr(C)]
78+
pub enum UnnamedAddr {
79+
No,
80+
Local,
81+
Global,
82+
}
83+
7684
/// LLVMDLLStorageClass
7785
#[derive(Copy, Clone)]
7886
#[repr(C)]
@@ -727,11 +735,11 @@ extern "C" {
727735
pub fn LLVMCloneModule(M: &Module) -> &Module;
728736

729737
/// Data layout. See Module::getDataLayout.
730-
pub fn LLVMGetDataLayout(M: &Module) -> *const c_char;
738+
pub fn LLVMGetDataLayoutStr(M: &Module) -> *const c_char;
731739
pub fn LLVMSetDataLayout(M: &Module, Triple: *const c_char);
732740

733741
/// See Module::setModuleInlineAsm.
734-
pub fn LLVMSetModuleInlineAsm(M: &Module, Asm: *const c_char);
742+
pub fn LLVMSetModuleInlineAsm2(M: &Module, Asm: *const c_char, AsmLen: size_t);
735743
pub fn LLVMRustAppendModuleInlineAsm(M: &Module, Asm: *const c_char, AsmLen: size_t);
736744

737745
/// See llvm::LLVMTypeKind::getTypeID.
@@ -1853,7 +1861,7 @@ extern "C" {
18531861
UniqueIdLen: size_t,
18541862
) -> &'a DIDerivedType;
18551863

1856-
pub fn LLVMSetUnnamedAddr(GlobalVar: &Value, UnnamedAddr: Bool);
1864+
pub fn LLVMSetUnnamedAddress(Global: &Value, UnnamedAddr: UnnamedAddr);
18571865

18581866
pub fn LLVMRustDIBuilderCreateTemplateTypeParameter(
18591867
Builder: &DIBuilder<'a>,

src/librustc_codegen_llvm/llvm/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ pub fn UnsetComdat(val: &'a Value) {
106106
}
107107
}
108108

109-
pub fn SetUnnamedAddr(global: &'a Value, unnamed: bool) {
109+
pub fn SetUnnamedAddress(global: &'a Value, unnamed: UnnamedAddr) {
110110
unsafe {
111-
LLVMSetUnnamedAddr(global, unnamed as Bool);
111+
LLVMSetUnnamedAddress(global, unnamed);
112112
}
113113
}
114114

0 commit comments

Comments
 (0)