Skip to content

Commit b09b114

Browse files
authored
Rollup merge of rust-lang#69940 - tmiasko:llvm-api, r=hanna-kruppe
librustc_codegen_llvm: Replace deprecated API usage
2 parents dc46a7f + 24dc2cb commit b09b114

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
@@ -166,7 +166,7 @@ pub unsafe fn create_module(
166166
llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm);
167167
llvm::LLVMRustDisposeTargetMachine(tm);
168168

169-
let llvm_data_layout = llvm::LLVMGetDataLayout(llmod);
169+
let llvm_data_layout = llvm::LLVMGetDataLayoutStr(llmod);
170170
let llvm_data_layout = str::from_utf8(CStr::from_ptr(llvm_data_layout).to_bytes())
171171
.expect("got a non-UTF8 data-layout from LLVM");
172172

@@ -458,7 +458,7 @@ impl CodegenCx<'b, 'tcx> {
458458
self.type_variadic_func(&[], ret)
459459
};
460460
let f = self.declare_cfn(name, fn_ty);
461-
llvm::SetUnnamedAddr(f, false);
461+
llvm::SetUnnamedAddress(f, llvm::UnnamedAddr::No);
462462
self.intrinsics.borrow_mut().insert(name, f);
463463
f
464464
}

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
@@ -1662,7 +1662,7 @@ fn generic_simd_intrinsic(
16621662
llvm_elem_vec_ty,
16631663
),
16641664
);
1665-
llvm::SetUnnamedAddr(f, false);
1665+
llvm::SetUnnamedAddress(f, llvm::UnnamedAddr::No);
16661666
let v = bx.call(f, &[args[1].immediate(), alignment, mask, args[0].immediate()], None);
16671667
return Ok(v);
16681668
}
@@ -1784,7 +1784,7 @@ fn generic_simd_intrinsic(
17841784
&llvm_intrinsic,
17851785
bx.type_func(&[llvm_elem_vec_ty, llvm_pointer_vec_ty, alignment_ty, mask_ty], ret_t),
17861786
);
1787-
llvm::SetUnnamedAddr(f, false);
1787+
llvm::SetUnnamedAddress(f, llvm::UnnamedAddr::No);
17881788
let v = bx.call(f, &[args[0].immediate(), args[1].immediate(), alignment, mask], None);
17891789
return Ok(v);
17901790
}
@@ -2083,7 +2083,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
20832083
let vec_ty = bx.cx.type_vector(elem_ty, in_len as u64);
20842084

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

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)