Use a safe wrapper around an LLVM FFI function
This commit is contained in:
parent
f16f64b15a
commit
3565603d25
5 changed files with 13 additions and 8 deletions
|
@ -533,7 +533,7 @@ pub(crate) fn inline_asm_call<'ll>(
|
||||||
))
|
))
|
||||||
}));
|
}));
|
||||||
let md = llvm::LLVMMDNodeInContext2(bx.llcx, srcloc.as_ptr(), srcloc.len());
|
let md = llvm::LLVMMDNodeInContext2(bx.llcx, srcloc.as_ptr(), srcloc.len());
|
||||||
let md = llvm::LLVMMetadataAsValue(&bx.llcx, md);
|
let md = bx.get_metadata_value(md);
|
||||||
llvm::LLVMSetMetadata(call, kind, md);
|
llvm::LLVMSetMetadata(call, kind, md);
|
||||||
|
|
||||||
Some(call)
|
Some(call)
|
||||||
|
|
|
@ -490,7 +490,7 @@ impl<'ll> CodegenCx<'ll, '_> {
|
||||||
llvm::LLVMMDStringInContext2(self.llcx, bytes.as_c_char_ptr(), bytes.len());
|
llvm::LLVMMDStringInContext2(self.llcx, bytes.as_c_char_ptr(), bytes.len());
|
||||||
let data = [section, alloc];
|
let data = [section, alloc];
|
||||||
let meta = llvm::LLVMMDNodeInContext2(self.llcx, data.as_ptr(), data.len());
|
let meta = llvm::LLVMMDNodeInContext2(self.llcx, data.as_ptr(), data.len());
|
||||||
let val = llvm::LLVMMetadataAsValue(self.llcx, meta);
|
let val = self.get_metadata_value(meta);
|
||||||
llvm::LLVMAddNamedMetadataOperand(
|
llvm::LLVMAddNamedMetadataOperand(
|
||||||
self.llmod,
|
self.llmod,
|
||||||
c"wasm.custom_sections".as_ptr(),
|
c"wasm.custom_sections".as_ptr(),
|
||||||
|
|
|
@ -656,7 +656,7 @@ impl<'ll> SimpleCx<'ll> {
|
||||||
|
|
||||||
impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
|
impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
|
||||||
pub(crate) fn get_metadata_value(&self, metadata: &'ll Metadata) -> &'ll Value {
|
pub(crate) fn get_metadata_value(&self, metadata: &'ll Metadata) -> &'ll Value {
|
||||||
unsafe { llvm::LLVMMetadataAsValue(self.llcx(), metadata) }
|
llvm::LLVMMetadataAsValue(self.llcx(), metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_function(&self, name: &str) -> Option<&'ll Value> {
|
pub(crate) fn get_function(&self, name: &str) -> Option<&'ll Value> {
|
||||||
|
@ -1225,9 +1225,14 @@ impl CodegenCx<'_, '_> {
|
||||||
|
|
||||||
impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
|
impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
|
||||||
/// A wrapper for [`llvm::LLVMSetMetadata`], but it takes `Metadata` as a parameter instead of `Value`.
|
/// 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) {
|
pub(crate) fn set_metadata<'a>(
|
||||||
|
&self,
|
||||||
|
val: &'a Value,
|
||||||
|
kind_id: MetadataType,
|
||||||
|
md: &'ll Metadata,
|
||||||
|
) {
|
||||||
|
let node = self.get_metadata_value(md);
|
||||||
unsafe {
|
unsafe {
|
||||||
let node = llvm::LLVMMetadataAsValue(self.llcx(), md);
|
|
||||||
llvm::LLVMSetMetadata(val, kind_id as c_uint, node);
|
llvm::LLVMSetMetadata(val, kind_id as c_uint, node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -649,7 +649,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
|
||||||
fn type_test(&mut self, pointer: Self::Value, typeid: Self::Metadata) -> 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) };
|
let typeid = self.get_metadata_value(typeid);
|
||||||
self.call_intrinsic("llvm.type.test", &[pointer, typeid])
|
self.call_intrinsic("llvm.type.test", &[pointer, typeid])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,7 +659,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
|
||||||
vtable_byte_offset: u64,
|
vtable_byte_offset: u64,
|
||||||
typeid: &'ll Metadata,
|
typeid: &'ll Metadata,
|
||||||
) -> Self::Value {
|
) -> Self::Value {
|
||||||
let typeid = unsafe { llvm::LLVMMetadataAsValue(&self.llcx, typeid) };
|
let typeid = self.get_metadata_value(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]);
|
||||||
|
|
|
@ -1680,7 +1680,7 @@ unsafe extern "C" {
|
||||||
Packed: Bool,
|
Packed: Bool,
|
||||||
);
|
);
|
||||||
|
|
||||||
pub(crate) fn LLVMMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;
|
pub(crate) safe fn LLVMMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;
|
||||||
|
|
||||||
pub(crate) fn LLVMSetUnnamedAddress(Global: &Value, UnnamedAddr: UnnamedAddr);
|
pub(crate) fn LLVMSetUnnamedAddress(Global: &Value, UnnamedAddr: UnnamedAddr);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue