Auto merge of #130389 - Luv-Ray:LLVMMDNodeInContext2, r=nikic
llvm: replace some deprecated functions `LLVMMDStringInContext` and `LLVMMDNodeInContext` are deprecated, replace them with `LLVMMDStringInContext2` and `LLVMMDNodeInContext2`. Also replace `Value` with `Metadata` in some function signatures for better consistency.
This commit is contained in:
commit
4cbfcf1b7f
@ -503,6 +503,7 @@ fn deref<'b>(&'b self) -> &'a Self::Target {
|
|||||||
|
|
||||||
impl<'gcc, 'tcx> BackendTypes for Builder<'_, 'gcc, 'tcx> {
|
impl<'gcc, 'tcx> BackendTypes for Builder<'_, 'gcc, 'tcx> {
|
||||||
type Value = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Value;
|
type Value = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Value;
|
||||||
|
type Metadata = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Metadata;
|
||||||
type Function = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Function;
|
type Function = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Function;
|
||||||
type BasicBlock = <CodegenCx<'gcc, 'tcx> as BackendTypes>::BasicBlock;
|
type BasicBlock = <CodegenCx<'gcc, 'tcx> as BackendTypes>::BasicBlock;
|
||||||
type Type = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Type;
|
type Type = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Type;
|
||||||
|
@ -414,6 +414,7 @@ pub fn bitcast_if_needed(
|
|||||||
|
|
||||||
impl<'gcc, 'tcx> BackendTypes for CodegenCx<'gcc, 'tcx> {
|
impl<'gcc, 'tcx> BackendTypes for CodegenCx<'gcc, 'tcx> {
|
||||||
type Value = RValue<'gcc>;
|
type Value = RValue<'gcc>;
|
||||||
|
type Metadata = RValue<'gcc>;
|
||||||
type Function = RValue<'gcc>;
|
type Function = RValue<'gcc>;
|
||||||
|
|
||||||
type BasicBlock = Block<'gcc>;
|
type BasicBlock = Block<'gcc>;
|
||||||
|
@ -504,10 +504,15 @@ pub(crate) fn inline_asm_call<'ll>(
|
|||||||
// due to the asm template string coming from a macro. LLVM will
|
// due to the asm template string coming from a macro. LLVM will
|
||||||
// default to the first srcloc for lines that don't have an
|
// default to the first srcloc for lines that don't have an
|
||||||
// associated srcloc.
|
// associated srcloc.
|
||||||
srcloc.push(bx.const_i32(0));
|
srcloc.push(llvm::LLVMValueAsMetadata(bx.const_i32(0)));
|
||||||
}
|
}
|
||||||
srcloc.extend(line_spans.iter().map(|span| bx.const_i32(span.lo().to_u32() as i32)));
|
srcloc.extend(
|
||||||
let md = llvm::LLVMMDNodeInContext(bx.llcx, srcloc.as_ptr(), srcloc.len() as u32);
|
line_spans
|
||||||
|
.iter()
|
||||||
|
.map(|span| llvm::LLVMValueAsMetadata(bx.const_i32(span.lo().to_u32() as i32))),
|
||||||
|
);
|
||||||
|
let md = llvm::LLVMMDNodeInContext2(bx.llcx, srcloc.as_ptr(), srcloc.len());
|
||||||
|
let md = llvm::LLVMMetadataAsValue(&bx.llcx, md);
|
||||||
llvm::LLVMSetMetadata(call, kind, md);
|
llvm::LLVMSetMetadata(call, kind, md);
|
||||||
|
|
||||||
Some(call)
|
Some(call)
|
||||||
|
@ -56,6 +56,7 @@ fn drop(&mut self) {
|
|||||||
|
|
||||||
impl<'ll, 'tcx> BackendTypes for Builder<'_, 'll, 'tcx> {
|
impl<'ll, 'tcx> BackendTypes for Builder<'_, 'll, 'tcx> {
|
||||||
type Value = <CodegenCx<'ll, 'tcx> as BackendTypes>::Value;
|
type Value = <CodegenCx<'ll, 'tcx> as BackendTypes>::Value;
|
||||||
|
type Metadata = <CodegenCx<'ll, 'tcx> as BackendTypes>::Metadata;
|
||||||
type Function = <CodegenCx<'ll, 'tcx> as BackendTypes>::Function;
|
type Function = <CodegenCx<'ll, 'tcx> as BackendTypes>::Function;
|
||||||
type BasicBlock = <CodegenCx<'ll, 'tcx> as BackendTypes>::BasicBlock;
|
type BasicBlock = <CodegenCx<'ll, 'tcx> as BackendTypes>::BasicBlock;
|
||||||
type Type = <CodegenCx<'ll, 'tcx> as BackendTypes>::Type;
|
type Type = <CodegenCx<'ll, 'tcx> as BackendTypes>::Type;
|
||||||
@ -623,26 +624,19 @@ fn range_metadata(&mut self, load: &'ll Value, range: WrappingRange) {
|
|||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let llty = self.cx.val_ty(load);
|
let llty = self.cx.val_ty(load);
|
||||||
let v = [
|
let md = [
|
||||||
self.cx.const_uint_big(llty, range.start),
|
llvm::LLVMValueAsMetadata(self.cx.const_uint_big(llty, range.start)),
|
||||||
self.cx.const_uint_big(llty, range.end.wrapping_add(1)),
|
llvm::LLVMValueAsMetadata(self.cx.const_uint_big(llty, range.end.wrapping_add(1))),
|
||||||
];
|
];
|
||||||
|
let md = llvm::LLVMMDNodeInContext2(self.cx.llcx, md.as_ptr(), md.len());
|
||||||
llvm::LLVMSetMetadata(
|
self.set_metadata(load, llvm::MD_range, md);
|
||||||
load,
|
|
||||||
llvm::MD_range as c_uint,
|
|
||||||
llvm::LLVMMDNodeInContext(self.cx.llcx, v.as_ptr(), v.len() as c_uint),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nonnull_metadata(&mut self, load: &'ll Value) {
|
fn nonnull_metadata(&mut self, load: &'ll Value) {
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMSetMetadata(
|
let md = llvm::LLVMMDNodeInContext2(self.cx.llcx, ptr::null(), 0);
|
||||||
load,
|
self.set_metadata(load, llvm::MD_nonnull, md);
|
||||||
llvm::MD_nonnull as c_uint,
|
|
||||||
llvm::LLVMMDNodeInContext(self.cx.llcx, ptr::null(), 0),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -690,9 +684,9 @@ fn store_with_flags(
|
|||||||
// *always* point to a metadata value of the integer 1.
|
// *always* point to a metadata value of the integer 1.
|
||||||
//
|
//
|
||||||
// [1]: https://llvm.org/docs/LangRef.html#store-instruction
|
// [1]: https://llvm.org/docs/LangRef.html#store-instruction
|
||||||
let one = self.cx.const_i32(1);
|
let one = llvm::LLVMValueAsMetadata(self.cx.const_i32(1));
|
||||||
let node = llvm::LLVMMDNodeInContext(self.cx.llcx, &one, 1);
|
let md = llvm::LLVMMDNodeInContext2(self.cx.llcx, &one, 1);
|
||||||
llvm::LLVMSetMetadata(store, llvm::MD_nontemporal as c_uint, node);
|
self.set_metadata(store, llvm::MD_nontemporal, md);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
store
|
store
|
||||||
@ -1157,11 +1151,8 @@ fn atomic_fence(
|
|||||||
|
|
||||||
fn set_invariant_load(&mut self, load: &'ll Value) {
|
fn set_invariant_load(&mut self, load: &'ll Value) {
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMSetMetadata(
|
let md = llvm::LLVMMDNodeInContext2(self.cx.llcx, ptr::null(), 0);
|
||||||
load,
|
self.set_metadata(load, llvm::MD_invariant_load, md);
|
||||||
llvm::MD_invariant_load as c_uint,
|
|
||||||
llvm::LLVMMDNodeInContext(self.cx.llcx, ptr::null(), 0),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1290,33 +1281,23 @@ fn position_at_start(&mut self, llbb: &'ll BasicBlock) {
|
|||||||
|
|
||||||
fn align_metadata(&mut self, load: &'ll Value, align: Align) {
|
fn align_metadata(&mut self, load: &'ll Value, align: Align) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let v = [self.cx.const_u64(align.bytes())];
|
let md = [llvm::LLVMValueAsMetadata(self.cx.const_u64(align.bytes()))];
|
||||||
|
let md = llvm::LLVMMDNodeInContext2(self.cx.llcx, md.as_ptr(), md.len());
|
||||||
llvm::LLVMSetMetadata(
|
self.set_metadata(load, llvm::MD_align, md);
|
||||||
load,
|
|
||||||
llvm::MD_align as c_uint,
|
|
||||||
llvm::LLVMMDNodeInContext(self.cx.llcx, v.as_ptr(), v.len() as c_uint),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn noundef_metadata(&mut self, load: &'ll Value) {
|
fn noundef_metadata(&mut self, load: &'ll Value) {
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMSetMetadata(
|
let md = llvm::LLVMMDNodeInContext2(self.cx.llcx, ptr::null(), 0);
|
||||||
load,
|
self.set_metadata(load, llvm::MD_noundef, md);
|
||||||
llvm::MD_noundef as c_uint,
|
|
||||||
llvm::LLVMMDNodeInContext(self.cx.llcx, ptr::null(), 0),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_unpredictable(&mut self, inst: &'ll Value) {
|
pub(crate) fn set_unpredictable(&mut self, inst: &'ll Value) {
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMSetMetadata(
|
let md = llvm::LLVMMDNodeInContext2(self.cx.llcx, ptr::null(), 0);
|
||||||
inst,
|
self.set_metadata(inst, llvm::MD_unpredictable, md);
|
||||||
llvm::MD_unpredictable as c_uint,
|
|
||||||
llvm::LLVMMDNodeInContext(self.cx.llcx, ptr::null(), 0),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
use crate::consts::const_alloc_to_llvm;
|
use crate::consts::const_alloc_to_llvm;
|
||||||
pub(crate) use crate::context::CodegenCx;
|
pub(crate) use crate::context::CodegenCx;
|
||||||
use crate::llvm::{self, BasicBlock, Bool, ConstantInt, False, OperandBundleDef, True};
|
use crate::llvm::{self, BasicBlock, Bool, ConstantInt, False, Metadata, OperandBundleDef, True};
|
||||||
use crate::type_::Type;
|
use crate::type_::Type;
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
|
|
||||||
@ -79,6 +79,7 @@ pub(crate) fn bundle(&self) -> &OperandBundleDef<'ll> {
|
|||||||
|
|
||||||
impl<'ll> BackendTypes for CodegenCx<'ll, '_> {
|
impl<'ll> BackendTypes for CodegenCx<'ll, '_> {
|
||||||
type Value = &'ll Value;
|
type Value = &'ll Value;
|
||||||
|
type Metadata = &'ll Metadata;
|
||||||
// FIXME(eddyb) replace this with a `Function` "subclass" of `Value`.
|
// FIXME(eddyb) replace this with a `Function` "subclass" of `Value`.
|
||||||
type Function = &'ll Value;
|
type Function = &'ll Value;
|
||||||
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::ffi::CStr;
|
use std::ffi::{CStr, c_uint};
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use libc::c_uint;
|
|
||||||
use rustc_codegen_ssa::base::{wants_msvc_seh, wants_wasm_eh};
|
use rustc_codegen_ssa::base::{wants_msvc_seh, wants_wasm_eh};
|
||||||
use rustc_codegen_ssa::errors as ssa_errors;
|
use rustc_codegen_ssa::errors as ssa_errors;
|
||||||
use rustc_codegen_ssa::traits::*;
|
use rustc_codegen_ssa::traits::*;
|
||||||
@ -31,6 +30,7 @@
|
|||||||
use crate::back::write::to_llvm_code_model;
|
use crate::back::write::to_llvm_code_model;
|
||||||
use crate::callee::get_fn;
|
use crate::callee::get_fn;
|
||||||
use crate::debuginfo::metadata::apply_vcall_visibility_metadata;
|
use crate::debuginfo::metadata::apply_vcall_visibility_metadata;
|
||||||
|
use crate::llvm::{Metadata, MetadataType};
|
||||||
use crate::type_::Type;
|
use crate::type_::Type;
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
use crate::{attributes, coverageinfo, debuginfo, llvm, llvm_util};
|
use crate::{attributes, coverageinfo, debuginfo, llvm, llvm_util};
|
||||||
@ -404,17 +404,17 @@ pub(crate) unsafe fn create_module<'ll>(
|
|||||||
let rustc_producer =
|
let rustc_producer =
|
||||||
format!("rustc version {}", option_env!("CFG_VERSION").expect("CFG_VERSION"));
|
format!("rustc version {}", option_env!("CFG_VERSION").expect("CFG_VERSION"));
|
||||||
let name_metadata = unsafe {
|
let name_metadata = unsafe {
|
||||||
llvm::LLVMMDStringInContext(
|
llvm::LLVMMDStringInContext2(
|
||||||
llcx,
|
llcx,
|
||||||
rustc_producer.as_ptr().cast(),
|
rustc_producer.as_ptr().cast(),
|
||||||
rustc_producer.as_bytes().len() as c_uint,
|
rustc_producer.as_bytes().len(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMAddNamedMetadataOperand(
|
llvm::LLVMAddNamedMetadataOperand(
|
||||||
llmod,
|
llmod,
|
||||||
c"llvm.ident".as_ptr(),
|
c"llvm.ident".as_ptr(),
|
||||||
llvm::LLVMMDNodeInContext(llcx, &name_metadata, 1),
|
&llvm::LLVMMetadataAsValue(llcx, llvm::LLVMMDNodeInContext2(llcx, &name_metadata, 1)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1119,6 +1119,14 @@ pub(crate) fn generate_local_symbol_name(&self, prefix: &str) -> String {
|
|||||||
name.push_str(&(idx as u64).to_base(ALPHANUMERIC_ONLY));
|
name.push_str(&(idx as u64).to_base(ALPHANUMERIC_ONLY));
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A wrapper for [`llvm::LLVMSetMetadata`], but it takes `Metadata` as a parameter instead of `Value`.
|
||||||
|
pub(crate) fn set_metadata<'a>(&self, val: &'a Value, kind_id: MetadataType, md: &'a Metadata) {
|
||||||
|
unsafe {
|
||||||
|
let node = llvm::LLVMMetadataAsValue(&self.llcx, md);
|
||||||
|
llvm::LLVMSetMetadata(val, kind_id as c_uint, node);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasDataLayout for CodegenCx<'_, '_> {
|
impl HasDataLayout for CodegenCx<'_, '_> {
|
||||||
|
@ -1547,20 +1547,16 @@ enum VCallVisibility {
|
|||||||
let trait_ref_typeid = typeid_for_trait_ref(cx.tcx, trait_ref);
|
let trait_ref_typeid = typeid_for_trait_ref(cx.tcx, trait_ref);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let typeid = llvm::LLVMMDStringInContext(
|
let typeid = llvm::LLVMMDStringInContext2(
|
||||||
cx.llcx,
|
cx.llcx,
|
||||||
trait_ref_typeid.as_ptr() as *const c_char,
|
trait_ref_typeid.as_ptr() as *const c_char,
|
||||||
trait_ref_typeid.as_bytes().len() as c_uint,
|
trait_ref_typeid.as_bytes().len(),
|
||||||
);
|
);
|
||||||
let v = [cx.const_usize(0), typeid];
|
let v = [llvm::LLVMValueAsMetadata(cx.const_usize(0)), typeid];
|
||||||
llvm::LLVMRustGlobalAddMetadata(
|
llvm::LLVMRustGlobalAddMetadata(
|
||||||
vtable,
|
vtable,
|
||||||
llvm::MD_type as c_uint,
|
llvm::MD_type as c_uint,
|
||||||
llvm::LLVMValueAsMetadata(llvm::LLVMMDNodeInContext(
|
llvm::LLVMMDNodeInContext2(cx.llcx, v.as_ptr(), v.len()),
|
||||||
cx.llcx,
|
|
||||||
v.as_ptr(),
|
|
||||||
v.len() as c_uint,
|
|
||||||
)),
|
|
||||||
);
|
);
|
||||||
let vcall_visibility = llvm::LLVMValueAsMetadata(cx.const_u64(vcall_visibility as u64));
|
let vcall_visibility = llvm::LLVMValueAsMetadata(cx.const_u64(vcall_visibility as u64));
|
||||||
let vcall_visibility_metadata = llvm::LLVMMDNodeInContext2(cx.llcx, &vcall_visibility, 1);
|
let vcall_visibility_metadata = llvm::LLVMMDNodeInContext2(cx.llcx, &vcall_visibility, 1);
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
use crate::abi::{Abi, FnAbi, FnAbiLlvmExt, LlvmType, PassMode};
|
use crate::abi::{Abi, FnAbi, FnAbiLlvmExt, LlvmType, PassMode};
|
||||||
use crate::builder::Builder;
|
use crate::builder::Builder;
|
||||||
use crate::context::CodegenCx;
|
use crate::context::CodegenCx;
|
||||||
use crate::llvm;
|
use crate::llvm::{self, Metadata};
|
||||||
use crate::type_::Type;
|
use crate::type_::Type;
|
||||||
use crate::type_of::LayoutLlvmExt;
|
use crate::type_of::LayoutLlvmExt;
|
||||||
use crate::va_arg::emit_va_arg;
|
use crate::va_arg::emit_va_arg;
|
||||||
@ -613,9 +613,10 @@ fn expect(&mut self, cond: Self::Value, expected: bool) -> Self::Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_test(&mut self, pointer: Self::Value, typeid: Self::Value) -> Self::Value {
|
fn type_test(&mut self, pointer: Self::Value, typeid: Self::Metadata) -> Self::Value {
|
||||||
// Test the called operand using llvm.type.test intrinsic. The LowerTypeTests link-time
|
// Test the called operand using llvm.type.test intrinsic. The LowerTypeTests link-time
|
||||||
// optimization pass replaces calls to this intrinsic with code to test type membership.
|
// optimization pass replaces calls to this intrinsic with code to test type membership.
|
||||||
|
let typeid = unsafe { llvm::LLVMMetadataAsValue(&self.llcx, typeid) };
|
||||||
self.call_intrinsic("llvm.type.test", &[pointer, typeid])
|
self.call_intrinsic("llvm.type.test", &[pointer, typeid])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -623,8 +624,9 @@ fn type_checked_load(
|
|||||||
&mut self,
|
&mut self,
|
||||||
llvtable: &'ll Value,
|
llvtable: &'ll Value,
|
||||||
vtable_byte_offset: u64,
|
vtable_byte_offset: u64,
|
||||||
typeid: &'ll Value,
|
typeid: &'ll Metadata,
|
||||||
) -> Self::Value {
|
) -> Self::Value {
|
||||||
|
let typeid = unsafe { llvm::LLVMMetadataAsValue(&self.llcx, typeid) };
|
||||||
let vtable_byte_offset = self.const_i32(vtable_byte_offset as i32);
|
let vtable_byte_offset = self.const_i32(vtable_byte_offset as i32);
|
||||||
let type_checked_load =
|
let type_checked_load =
|
||||||
self.call_intrinsic("llvm.type.checked.load", &[llvtable, vtable_byte_offset, typeid]);
|
self.call_intrinsic("llvm.type.checked.load", &[llvtable, vtable_byte_offset, typeid]);
|
||||||
|
@ -885,17 +885,7 @@ pub fn LLVMStructTypeInContext<'a>(
|
|||||||
pub fn LLVMGetPoison(Ty: &Type) -> &Value;
|
pub fn LLVMGetPoison(Ty: &Type) -> &Value;
|
||||||
|
|
||||||
// Operations on metadata
|
// Operations on metadata
|
||||||
// FIXME: deprecated, replace with LLVMMDStringInContext2
|
|
||||||
pub fn LLVMMDStringInContext(C: &Context, Str: *const c_char, SLen: c_uint) -> &Value;
|
|
||||||
|
|
||||||
pub fn LLVMMDStringInContext2(C: &Context, Str: *const c_char, SLen: size_t) -> &Metadata;
|
pub fn LLVMMDStringInContext2(C: &Context, Str: *const c_char, SLen: size_t) -> &Metadata;
|
||||||
|
|
||||||
// FIXME: deprecated, replace with LLVMMDNodeInContext2
|
|
||||||
pub fn LLVMMDNodeInContext<'a>(
|
|
||||||
C: &'a Context,
|
|
||||||
Vals: *const &'a Value,
|
|
||||||
Count: c_uint,
|
|
||||||
) -> &'a Value;
|
|
||||||
pub fn LLVMMDNodeInContext2<'a>(
|
pub fn LLVMMDNodeInContext2<'a>(
|
||||||
C: &'a Context,
|
C: &'a Context,
|
||||||
Vals: *const &'a Metadata,
|
Vals: *const &'a Metadata,
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
use crate::abi::{FnAbiLlvmExt, LlvmType};
|
use crate::abi::{FnAbiLlvmExt, LlvmType};
|
||||||
use crate::context::CodegenCx;
|
use crate::context::CodegenCx;
|
||||||
pub(crate) use crate::llvm::Type;
|
pub(crate) use crate::llvm::Type;
|
||||||
use crate::llvm::{Bool, False, True};
|
use crate::llvm::{Bool, False, Metadata, True};
|
||||||
use crate::type_of::LayoutLlvmExt;
|
use crate::type_of::LayoutLlvmExt;
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
use crate::{common, llvm};
|
use crate::{common, llvm};
|
||||||
@ -283,43 +283,31 @@ fn reg_backend_type(&self, ty: &Reg) -> &'ll Type {
|
|||||||
impl<'ll, 'tcx> TypeMembershipCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
impl<'ll, 'tcx> TypeMembershipCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
||||||
fn add_type_metadata(&self, function: &'ll Value, typeid: String) {
|
fn add_type_metadata(&self, function: &'ll Value, typeid: String) {
|
||||||
let typeid_metadata = self.typeid_metadata(typeid).unwrap();
|
let typeid_metadata = self.typeid_metadata(typeid).unwrap();
|
||||||
let v = [self.const_usize(0), typeid_metadata];
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
let v = [llvm::LLVMValueAsMetadata(self.const_usize(0)), typeid_metadata];
|
||||||
llvm::LLVMRustGlobalAddMetadata(
|
llvm::LLVMRustGlobalAddMetadata(
|
||||||
function,
|
function,
|
||||||
llvm::MD_type as c_uint,
|
llvm::MD_type as c_uint,
|
||||||
llvm::LLVMValueAsMetadata(llvm::LLVMMDNodeInContext(
|
llvm::LLVMMDNodeInContext2(self.llcx, v.as_ptr(), v.len()),
|
||||||
self.llcx,
|
|
||||||
v.as_ptr(),
|
|
||||||
v.len() as c_uint,
|
|
||||||
)),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_type_metadata(&self, function: &'ll Value, typeid: String) {
|
fn set_type_metadata(&self, function: &'ll Value, typeid: String) {
|
||||||
let typeid_metadata = self.typeid_metadata(typeid).unwrap();
|
let typeid_metadata = self.typeid_metadata(typeid).unwrap();
|
||||||
let v = [self.const_usize(0), typeid_metadata];
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
let v = [llvm::LLVMValueAsMetadata(self.const_usize(0)), typeid_metadata];
|
||||||
llvm::LLVMGlobalSetMetadata(
|
llvm::LLVMGlobalSetMetadata(
|
||||||
function,
|
function,
|
||||||
llvm::MD_type as c_uint,
|
llvm::MD_type as c_uint,
|
||||||
llvm::LLVMValueAsMetadata(llvm::LLVMMDNodeInContext(
|
llvm::LLVMMDNodeInContext2(self.llcx, v.as_ptr(), v.len()),
|
||||||
self.llcx,
|
|
||||||
v.as_ptr(),
|
|
||||||
v.len() as c_uint,
|
|
||||||
)),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn typeid_metadata(&self, typeid: String) -> Option<&'ll Value> {
|
fn typeid_metadata(&self, typeid: String) -> Option<&'ll Metadata> {
|
||||||
Some(unsafe {
|
Some(unsafe {
|
||||||
llvm::LLVMMDStringInContext(
|
llvm::LLVMMDStringInContext2(self.llcx, typeid.as_ptr() as *const c_char, typeid.len())
|
||||||
self.llcx,
|
|
||||||
typeid.as_ptr() as *const c_char,
|
|
||||||
typeid.len() as c_uint,
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
pub trait BackendTypes {
|
pub trait BackendTypes {
|
||||||
type Value: CodegenObject;
|
type Value: CodegenObject;
|
||||||
|
type Metadata: CodegenObject;
|
||||||
type Function: CodegenObject;
|
type Function: CodegenObject;
|
||||||
|
|
||||||
type BasicBlock: Copy;
|
type BasicBlock: Copy;
|
||||||
|
@ -51,6 +51,7 @@ pub trait BuilderMethods<'a, 'tcx>:
|
|||||||
type CodegenCx: CodegenMethods<
|
type CodegenCx: CodegenMethods<
|
||||||
'tcx,
|
'tcx,
|
||||||
Value = Self::Value,
|
Value = Self::Value,
|
||||||
|
Metadata = Self::Metadata,
|
||||||
Function = Self::Function,
|
Function = Self::Function,
|
||||||
BasicBlock = Self::BasicBlock,
|
BasicBlock = Self::BasicBlock,
|
||||||
Type = Self::Type,
|
Type = Self::Type,
|
||||||
|
@ -24,14 +24,14 @@ fn codegen_intrinsic_call(
|
|||||||
fn assume(&mut self, val: Self::Value);
|
fn assume(&mut self, val: Self::Value);
|
||||||
fn expect(&mut self, cond: Self::Value, expected: bool) -> Self::Value;
|
fn expect(&mut self, cond: Self::Value, expected: bool) -> Self::Value;
|
||||||
/// Trait method used to test whether a given pointer is associated with a type identifier.
|
/// Trait method used to test whether a given pointer is associated with a type identifier.
|
||||||
fn type_test(&mut self, pointer: Self::Value, typeid: Self::Value) -> Self::Value;
|
fn type_test(&mut self, pointer: Self::Value, typeid: Self::Metadata) -> Self::Value;
|
||||||
/// Trait method used to load a function while testing if it is associated with a type
|
/// Trait method used to load a function while testing if it is associated with a type
|
||||||
/// identifier.
|
/// identifier.
|
||||||
fn type_checked_load(
|
fn type_checked_load(
|
||||||
&mut self,
|
&mut self,
|
||||||
llvtable: Self::Value,
|
llvtable: Self::Value,
|
||||||
vtable_byte_offset: u64,
|
vtable_byte_offset: u64,
|
||||||
typeid: Self::Value,
|
typeid: Self::Metadata,
|
||||||
) -> Self::Value;
|
) -> Self::Value;
|
||||||
/// Trait method used to inject `va_start` on the "spoofed" `VaListImpl` in
|
/// Trait method used to inject `va_start` on the "spoofed" `VaListImpl` in
|
||||||
/// Rust defined C-variadic functions.
|
/// Rust defined C-variadic functions.
|
||||||
|
@ -152,7 +152,7 @@ fn is_backend_ref(&self, layout: TyAndLayout<'tcx>) -> bool {
|
|||||||
pub trait TypeMembershipCodegenMethods<'tcx>: BackendTypes {
|
pub trait TypeMembershipCodegenMethods<'tcx>: BackendTypes {
|
||||||
fn add_type_metadata(&self, _function: Self::Function, _typeid: String) {}
|
fn add_type_metadata(&self, _function: Self::Function, _typeid: String) {}
|
||||||
fn set_type_metadata(&self, _function: Self::Function, _typeid: String) {}
|
fn set_type_metadata(&self, _function: Self::Function, _typeid: String) {}
|
||||||
fn typeid_metadata(&self, _typeid: String) -> Option<Self::Value> {
|
fn typeid_metadata(&self, _typeid: String) -> Option<Self::Metadata> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
fn add_kcfi_type_metadata(&self, _function: Self::Function, _typeid: u32) {}
|
fn add_kcfi_type_metadata(&self, _function: Self::Function, _typeid: u32) {}
|
||||||
|
Loading…
Reference in New Issue
Block a user