Skip to content

Commit b7c5656

Browse files
committed
replace some deprecated functions
1 parent a5cf8bb commit b7c5656

File tree

14 files changed

+61
-87
lines changed

14 files changed

+61
-87
lines changed

compiler/rustc_codegen_gcc/src/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ impl<'a, 'gcc, 'tcx> Deref for Builder<'a, 'gcc, 'tcx> {
500500

501501
impl<'gcc, 'tcx> BackendTypes for Builder<'_, 'gcc, 'tcx> {
502502
type Value = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Value;
503+
type Metadata = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Metadata;
503504
type Function = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Function;
504505
type BasicBlock = <CodegenCx<'gcc, 'tcx> as BackendTypes>::BasicBlock;
505506
type Type = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Type;

compiler/rustc_codegen_gcc/src/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
414414

415415
impl<'gcc, 'tcx> BackendTypes for CodegenCx<'gcc, 'tcx> {
416416
type Value = RValue<'gcc>;
417+
type Metadata = RValue<'gcc>;
417418
type Function = RValue<'gcc>;
418419

419420
type BasicBlock = Block<'gcc>;

compiler/rustc_codegen_llvm/src/asm.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,15 @@ pub(crate) fn inline_asm_call<'ll>(
504504
// due to the asm template string coming from a macro. LLVM will
505505
// default to the first srcloc for lines that don't have an
506506
// associated srcloc.
507-
srcloc.push(bx.const_i32(0));
507+
srcloc.push(llvm::LLVMValueAsMetadata(bx.const_i32(0)));
508508
}
509-
srcloc.extend(line_spans.iter().map(|span| bx.const_i32(span.lo().to_u32() as i32)));
510-
let md = llvm::LLVMMDNodeInContext(bx.llcx, srcloc.as_ptr(), srcloc.len() as u32);
509+
srcloc.extend(
510+
line_spans
511+
.iter()
512+
.map(|span| llvm::LLVMValueAsMetadata(bx.const_i32(span.lo().to_u32() as i32))),
513+
);
514+
let md = llvm::LLVMMDNodeInContext2(bx.llcx, srcloc.as_ptr(), srcloc.len());
515+
let md = llvm::LLVMMetadataAsValue(&bx.llcx, md);
511516
llvm::LLVMSetMetadata(call, kind, md);
512517

513518
Some(call)

compiler/rustc_codegen_llvm/src/builder.rs

+25-36
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const UNNAMED: *const c_char = c"".as_ptr();
5656

5757
impl<'ll, 'tcx> BackendTypes for Builder<'_, 'll, 'tcx> {
5858
type Value = <CodegenCx<'ll, 'tcx> as BackendTypes>::Value;
59+
type Metadata = <CodegenCx<'ll, 'tcx> as BackendTypes>::Metadata;
5960
type Function = <CodegenCx<'ll, 'tcx> as BackendTypes>::Function;
6061
type BasicBlock = <CodegenCx<'ll, 'tcx> as BackendTypes>::BasicBlock;
6162
type Type = <CodegenCx<'ll, 'tcx> as BackendTypes>::Type;
@@ -678,25 +679,21 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
678679
unsafe {
679680
let llty = self.cx.val_ty(load);
680681
let v = [
681-
self.cx.const_uint_big(llty, range.start),
682-
self.cx.const_uint_big(llty, range.end.wrapping_add(1)),
682+
llvm::LLVMValueAsMetadata(self.cx.const_uint_big(llty, range.start)),
683+
llvm::LLVMValueAsMetadata(self.cx.const_uint_big(llty, range.end.wrapping_add(1))),
683684
];
684685

685-
llvm::LLVMSetMetadata(
686-
load,
687-
llvm::MD_range as c_uint,
688-
llvm::LLVMMDNodeInContext(self.cx.llcx, v.as_ptr(), v.len() as c_uint),
689-
);
686+
let md = llvm::LLVMMDNodeInContext2(self.cx.llcx, v.as_ptr(), v.len());
687+
let md = llvm::LLVMMetadataAsValue(&self.llcx, md);
688+
llvm::LLVMSetMetadata(load, llvm::MD_range as c_uint, md);
690689
}
691690
}
692691

693692
fn nonnull_metadata(&mut self, load: &'ll Value) {
694693
unsafe {
695-
llvm::LLVMSetMetadata(
696-
load,
697-
llvm::MD_nonnull as c_uint,
698-
llvm::LLVMMDNodeInContext(self.cx.llcx, ptr::null(), 0),
699-
);
694+
let md = llvm::LLVMMDNodeInContext2(self.cx.llcx, ptr::null(), 0);
695+
let md = llvm::LLVMMetadataAsValue(&self.llcx, md);
696+
llvm::LLVMSetMetadata(load, llvm::MD_nonnull as c_uint, md);
700697
}
701698
}
702699

@@ -744,8 +741,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
744741
// *always* point to a metadata value of the integer 1.
745742
//
746743
// [1]: https://llvm.org/docs/LangRef.html#store-instruction
747-
let one = self.cx.const_i32(1);
748-
let node = llvm::LLVMMDNodeInContext(self.cx.llcx, &one, 1);
744+
let one = llvm::LLVMValueAsMetadata(self.cx.const_i32(1));
745+
let node = llvm::LLVMMDNodeInContext2(self.cx.llcx, &one, 1);
746+
let node = llvm::LLVMMetadataAsValue(&self.llcx, node);
749747
llvm::LLVMSetMetadata(store, llvm::MD_nontemporal as c_uint, node);
750748
}
751749
}
@@ -1210,11 +1208,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
12101208

12111209
fn set_invariant_load(&mut self, load: &'ll Value) {
12121210
unsafe {
1213-
llvm::LLVMSetMetadata(
1214-
load,
1215-
llvm::MD_invariant_load as c_uint,
1216-
llvm::LLVMMDNodeInContext(self.cx.llcx, ptr::null(), 0),
1217-
);
1211+
let md = llvm::LLVMMDNodeInContext2(self.cx.llcx, ptr::null(), 0);
1212+
let md = llvm::LLVMMetadataAsValue(&self.llcx, md);
1213+
llvm::LLVMSetMetadata(load, llvm::MD_invariant_load as c_uint, md);
12181214
}
12191215
}
12201216

@@ -1343,33 +1339,26 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
13431339

13441340
fn align_metadata(&mut self, load: &'ll Value, align: Align) {
13451341
unsafe {
1346-
let v = [self.cx.const_u64(align.bytes())];
1347-
1348-
llvm::LLVMSetMetadata(
1349-
load,
1350-
llvm::MD_align as c_uint,
1351-
llvm::LLVMMDNodeInContext(self.cx.llcx, v.as_ptr(), v.len() as c_uint),
1352-
);
1342+
let v = [llvm::LLVMValueAsMetadata(self.cx.const_u64(align.bytes()))];
1343+
let md = llvm::LLVMMDNodeInContext2(self.cx.llcx, v.as_ptr(), v.len());
1344+
let md = llvm::LLVMMetadataAsValue(&self.llcx, md);
1345+
llvm::LLVMSetMetadata(load, llvm::MD_align as c_uint, md);
13531346
}
13541347
}
13551348

13561349
fn noundef_metadata(&mut self, load: &'ll Value) {
13571350
unsafe {
1358-
llvm::LLVMSetMetadata(
1359-
load,
1360-
llvm::MD_noundef as c_uint,
1361-
llvm::LLVMMDNodeInContext(self.cx.llcx, ptr::null(), 0),
1362-
);
1351+
let md = llvm::LLVMMDNodeInContext2(self.cx.llcx, ptr::null(), 0);
1352+
let md = llvm::LLVMMetadataAsValue(&self.llcx, md);
1353+
llvm::LLVMSetMetadata(load, llvm::MD_noundef as c_uint, md);
13631354
}
13641355
}
13651356

13661357
pub(crate) fn set_unpredictable(&mut self, inst: &'ll Value) {
13671358
unsafe {
1368-
llvm::LLVMSetMetadata(
1369-
inst,
1370-
llvm::MD_unpredictable as c_uint,
1371-
llvm::LLVMMDNodeInContext(self.cx.llcx, ptr::null(), 0),
1372-
);
1359+
let md = llvm::LLVMMDNodeInContext2(self.cx.llcx, ptr::null(), 0);
1360+
let md = llvm::LLVMMetadataAsValue(&self.llcx, md);
1361+
llvm::LLVMSetMetadata(inst, llvm::MD_unpredictable as c_uint, md);
13731362
}
13741363
}
13751364

compiler/rustc_codegen_llvm/src/common.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use tracing::debug;
1414

1515
use crate::consts::const_alloc_to_llvm;
1616
pub(crate) use crate::context::CodegenCx;
17-
use crate::llvm::{self, BasicBlock, Bool, ConstantInt, False, OperandBundleDef, True};
17+
use crate::llvm::{self, BasicBlock, Bool, ConstantInt, False, Metadata, OperandBundleDef, True};
1818
use crate::type_::Type;
1919
use crate::value::Value;
2020

@@ -79,6 +79,7 @@ impl<'ll> Funclet<'ll> {
7979

8080
impl<'ll> BackendTypes for CodegenCx<'ll, '_> {
8181
type Value = &'ll Value;
82+
type Metadata = &'ll Metadata;
8283
// FIXME(eddyb) replace this with a `Function` "subclass" of `Value`.
8384
type Function = &'ll Value;
8485

compiler/rustc_codegen_llvm/src/context.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::cell::{Cell, RefCell};
33
use std::ffi::CStr;
44
use std::str;
55

6-
use libc::c_uint;
76
use rustc_codegen_ssa::base::{wants_msvc_seh, wants_wasm_eh};
87
use rustc_codegen_ssa::errors as ssa_errors;
98
use rustc_codegen_ssa::traits::*;
@@ -403,17 +402,17 @@ pub(crate) unsafe fn create_module<'ll>(
403402
let rustc_producer =
404403
format!("rustc version {}", option_env!("CFG_VERSION").expect("CFG_VERSION"));
405404
let name_metadata = unsafe {
406-
llvm::LLVMMDStringInContext(
405+
llvm::LLVMMDStringInContext2(
407406
llcx,
408407
rustc_producer.as_ptr().cast(),
409-
rustc_producer.as_bytes().len() as c_uint,
408+
rustc_producer.as_bytes().len(),
410409
)
411410
};
412411
unsafe {
413412
llvm::LLVMAddNamedMetadataOperand(
414413
llmod,
415414
c"llvm.ident".as_ptr(),
416-
llvm::LLVMMDNodeInContext(llcx, &name_metadata, 1),
415+
&llvm::LLVMMetadataAsValue(llcx, llvm::LLVMMDNodeInContext2(llcx, &name_metadata, 1)),
417416
);
418417
}
419418

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -1545,20 +1545,16 @@ pub(crate) fn apply_vcall_visibility_metadata<'ll, 'tcx>(
15451545
let trait_ref_typeid = typeid_for_trait_ref(cx.tcx, trait_ref);
15461546

15471547
unsafe {
1548-
let typeid = llvm::LLVMMDStringInContext(
1548+
let typeid = llvm::LLVMMDStringInContext2(
15491549
cx.llcx,
15501550
trait_ref_typeid.as_ptr() as *const c_char,
1551-
trait_ref_typeid.as_bytes().len() as c_uint,
1551+
trait_ref_typeid.as_bytes().len(),
15521552
);
1553-
let v = [cx.const_usize(0), typeid];
1553+
let v = [llvm::LLVMValueAsMetadata(cx.const_usize(0)), typeid];
15541554
llvm::LLVMRustGlobalAddMetadata(
15551555
vtable,
15561556
llvm::MD_type as c_uint,
1557-
llvm::LLVMValueAsMetadata(llvm::LLVMMDNodeInContext(
1558-
cx.llcx,
1559-
v.as_ptr(),
1560-
v.len() as c_uint,
1561-
)),
1557+
llvm::LLVMMDNodeInContext2(cx.llcx, v.as_ptr(), v.len()),
15621558
);
15631559
let vcall_visibility = llvm::LLVMValueAsMetadata(cx.const_u64(vcall_visibility as u64));
15641560
let vcall_visibility_metadata = llvm::LLVMMDNodeInContext2(cx.llcx, &vcall_visibility, 1);

compiler/rustc_codegen_llvm/src/intrinsic.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use tracing::debug;
2020
use crate::abi::{Abi, FnAbi, FnAbiLlvmExt, LlvmType, PassMode};
2121
use crate::builder::Builder;
2222
use crate::context::CodegenCx;
23-
use crate::llvm;
23+
use crate::llvm::{self, Metadata};
2424
use crate::type_::Type;
2525
use crate::type_of::LayoutLlvmExt;
2626
use crate::va_arg::emit_va_arg;
@@ -616,18 +616,20 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
616616
}
617617
}
618618

619-
fn type_test(&mut self, pointer: Self::Value, typeid: Self::Value) -> Self::Value {
619+
fn type_test(&mut self, pointer: Self::Value, typeid: Self::Metadata) -> Self::Value {
620620
// Test the called operand using llvm.type.test intrinsic. The LowerTypeTests link-time
621621
// optimization pass replaces calls to this intrinsic with code to test type membership.
622+
let typeid = unsafe { llvm::LLVMMetadataAsValue(&self.llcx, typeid) };
622623
self.call_intrinsic("llvm.type.test", &[pointer, typeid])
623624
}
624625

625626
fn type_checked_load(
626627
&mut self,
627628
llvtable: &'ll Value,
628629
vtable_byte_offset: u64,
629-
typeid: &'ll Value,
630+
typeid: &'ll Metadata,
630631
) -> Self::Value {
632+
let typeid = unsafe { llvm::LLVMMetadataAsValue(&self.llcx, typeid) };
631633
let vtable_byte_offset = self.const_i32(vtable_byte_offset as i32);
632634
let type_checked_load =
633635
self.call_intrinsic("llvm.type.checked.load", &[llvtable, vtable_byte_offset, typeid]);

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

-10
Original file line numberDiff line numberDiff line change
@@ -912,17 +912,7 @@ unsafe extern "C" {
912912
pub fn LLVMGetPoison(Ty: &Type) -> &Value;
913913

914914
// Operations on metadata
915-
// FIXME: deprecated, replace with LLVMMDStringInContext2
916-
pub fn LLVMMDStringInContext(C: &Context, Str: *const c_char, SLen: c_uint) -> &Value;
917-
918915
pub fn LLVMMDStringInContext2(C: &Context, Str: *const c_char, SLen: size_t) -> &Metadata;
919-
920-
// FIXME: deprecated, replace with LLVMMDNodeInContext2
921-
pub fn LLVMMDNodeInContext<'a>(
922-
C: &'a Context,
923-
Vals: *const &'a Value,
924-
Count: c_uint,
925-
) -> &'a Value;
926916
pub fn LLVMMDNodeInContext2<'a>(
927917
C: &'a Context,
928918
Vals: *const &'a Metadata,

compiler/rustc_codegen_llvm/src/type_.rs

+7-19
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_target::abi::{AddressSpace, Align, Integer, Size};
1313
use crate::abi::{FnAbiLlvmExt, LlvmType};
1414
use crate::context::CodegenCx;
1515
pub(crate) use crate::llvm::Type;
16-
use crate::llvm::{Bool, False, True};
16+
use crate::llvm::{Bool, False, Metadata, True};
1717
use crate::type_of::LayoutLlvmExt;
1818
use crate::value::Value;
1919
use crate::{common, llvm};
@@ -283,43 +283,31 @@ impl<'ll, 'tcx> LayoutTypeCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
283283
impl<'ll, 'tcx> TypeMembershipCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
284284
fn add_type_metadata(&self, function: &'ll Value, typeid: String) {
285285
let typeid_metadata = self.typeid_metadata(typeid).unwrap();
286-
let v = [self.const_usize(0), typeid_metadata];
287286
unsafe {
287+
let v = [llvm::LLVMValueAsMetadata(self.const_usize(0)), typeid_metadata];
288288
llvm::LLVMRustGlobalAddMetadata(
289289
function,
290290
llvm::MD_type as c_uint,
291-
llvm::LLVMValueAsMetadata(llvm::LLVMMDNodeInContext(
292-
self.llcx,
293-
v.as_ptr(),
294-
v.len() as c_uint,
295-
)),
291+
llvm::LLVMMDNodeInContext2(self.llcx, v.as_ptr(), v.len()),
296292
)
297293
}
298294
}
299295

300296
fn set_type_metadata(&self, function: &'ll Value, typeid: String) {
301297
let typeid_metadata = self.typeid_metadata(typeid).unwrap();
302-
let v = [self.const_usize(0), typeid_metadata];
303298
unsafe {
299+
let v = [llvm::LLVMValueAsMetadata(self.const_usize(0)), typeid_metadata];
304300
llvm::LLVMGlobalSetMetadata(
305301
function,
306302
llvm::MD_type as c_uint,
307-
llvm::LLVMValueAsMetadata(llvm::LLVMMDNodeInContext(
308-
self.llcx,
309-
v.as_ptr(),
310-
v.len() as c_uint,
311-
)),
303+
llvm::LLVMMDNodeInContext2(self.llcx, v.as_ptr(), v.len()),
312304
)
313305
}
314306
}
315307

316-
fn typeid_metadata(&self, typeid: String) -> Option<&'ll Value> {
308+
fn typeid_metadata(&self, typeid: String) -> Option<&'ll Metadata> {
317309
Some(unsafe {
318-
llvm::LLVMMDStringInContext(
319-
self.llcx,
320-
typeid.as_ptr() as *const c_char,
321-
typeid.len() as c_uint,
322-
)
310+
llvm::LLVMMDStringInContext2(self.llcx, typeid.as_ptr() as *const c_char, typeid.len())
323311
})
324312
}
325313

compiler/rustc_codegen_ssa/src/traits/backend.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::{CodegenResults, ModuleCodegen};
2121

2222
pub trait BackendTypes {
2323
type Value: CodegenObject;
24+
type Metadata: CodegenObject;
2425
type Function: CodegenObject;
2526

2627
type BasicBlock: Copy;

compiler/rustc_codegen_ssa/src/traits/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub trait BuilderMethods<'a, 'tcx>:
5151
type CodegenCx: CodegenMethods<
5252
'tcx,
5353
Value = Self::Value,
54+
Metadata = Self::Metadata,
5455
Function = Self::Function,
5556
BasicBlock = Self::BasicBlock,
5657
Type = Self::Type,

compiler/rustc_codegen_ssa/src/traits/intrinsic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ pub trait IntrinsicCallBuilderMethods<'tcx>: BackendTypes {
2424
fn assume(&mut self, val: Self::Value);
2525
fn expect(&mut self, cond: Self::Value, expected: bool) -> Self::Value;
2626
/// Trait method used to test whether a given pointer is associated with a type identifier.
27-
fn type_test(&mut self, pointer: Self::Value, typeid: Self::Value) -> Self::Value;
27+
fn type_test(&mut self, pointer: Self::Value, typeid: Self::Metadata) -> Self::Value;
2828
/// Trait method used to load a function while testing if it is associated with a type
2929
/// identifier.
3030
fn type_checked_load(
3131
&mut self,
3232
llvtable: Self::Value,
3333
vtable_byte_offset: u64,
34-
typeid: Self::Value,
34+
typeid: Self::Metadata,
3535
) -> Self::Value;
3636
/// Trait method used to inject `va_start` on the "spoofed" `VaListImpl` in
3737
/// Rust defined C-variadic functions.

compiler/rustc_codegen_ssa/src/traits/type_.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub trait LayoutTypeCodegenMethods<'tcx>: BackendTypes {
152152
pub trait TypeMembershipCodegenMethods<'tcx>: BackendTypes {
153153
fn add_type_metadata(&self, _function: Self::Function, _typeid: String) {}
154154
fn set_type_metadata(&self, _function: Self::Function, _typeid: String) {}
155-
fn typeid_metadata(&self, _typeid: String) -> Option<Self::Value> {
155+
fn typeid_metadata(&self, _typeid: String) -> Option<Self::Metadata> {
156156
None
157157
}
158158
fn add_kcfi_type_metadata(&self, _function: Self::Function, _typeid: u32) {}

0 commit comments

Comments
 (0)