-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 2) #136632
base: master
Are you sure you want to change the base?
Changes from all commits
1add0bc
14397b7
af26bf5
9d350cd
5eecd47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
//! Safe wrappers for [`DIBuilder`] FFI functions. | ||
|
||
use libc::c_uint; | ||
use rustc_abi::{Align, Size}; | ||
|
||
use crate::llvm::debuginfo::{DIBuilder, DIFlags}; | ||
use crate::llvm::{self, Metadata}; | ||
|
||
impl<'ll> DIBuilder<'ll> { | ||
pub(crate) fn create_subroutine_type( | ||
&self, | ||
parameter_types: &[Option<&'ll Metadata>], | ||
flags: DIFlags, | ||
) -> &'ll Metadata { | ||
unsafe { | ||
llvm::LLVMDIBuilderCreateSubroutineType( | ||
self, | ||
Comment on lines
+15
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, so, it's somewhat hard to audit the safe wrappers if I don't know what safety constraints they are filling. I can guess, but I shouldn't have to. Either there should be safety comments on the wrapper decls or they should be on this block, so that future additions to these functions don't fuck up and change the parts of the code that have to be a certain way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like it could be, idk, instead of exhaustively listing param relationships // SAFETY: this call is safe if we know the DIBuilder is live, which we do because
// we have it by-ref, and the rest is just translating slices to two params |
||
None, // ("File"; unused) | ||
parameter_types.as_ptr(), | ||
parameter_types.len() as c_uint, | ||
flags, | ||
) | ||
} | ||
} | ||
|
||
pub(crate) fn create_union_type( | ||
&self, | ||
scope: Option<&'ll Metadata>, | ||
name: &str, | ||
file_metadata: &'ll Metadata, | ||
line_number: c_uint, | ||
size: Size, | ||
align: Align, | ||
flags: DIFlags, | ||
elements: &[&'ll Metadata], | ||
unique_id: &str, | ||
) -> &'ll Metadata { | ||
unsafe { | ||
llvm::LLVMDIBuilderCreateUnionType( | ||
self, | ||
scope, | ||
name.as_ptr(), | ||
name.len(), | ||
file_metadata, | ||
line_number, | ||
size.bits(), | ||
align.bits() as u32, | ||
flags, | ||
elements.as_ptr(), | ||
elements.len() as c_uint, | ||
0, // ("Objective-C runtime version"; default is 0) | ||
unique_id.as_ptr(), | ||
unique_id.len(), | ||
) | ||
} | ||
} | ||
|
||
pub(crate) fn create_array_type( | ||
&self, | ||
size: Size, | ||
align: Align, | ||
element_type: &'ll Metadata, | ||
subscripts: &[&'ll Metadata], | ||
) -> &'ll Metadata { | ||
unsafe { | ||
llvm::LLVMDIBuilderCreateArrayType( | ||
self, | ||
size.bits(), | ||
align.bits() as u32, | ||
element_type, | ||
subscripts.as_ptr(), | ||
subscripts.len() as c_uint, | ||
) | ||
} | ||
} | ||
|
||
pub(crate) fn create_basic_type( | ||
&self, | ||
name: &str, | ||
size: Size, | ||
dwarf_type_encoding: u32, | ||
flags: DIFlags, | ||
) -> &'ll Metadata { | ||
unsafe { | ||
llvm::LLVMDIBuilderCreateBasicType( | ||
self, | ||
name.as_ptr(), | ||
name.len(), | ||
size.bits(), | ||
dwarf_type_encoding, | ||
flags, | ||
) | ||
} | ||
} | ||
|
||
pub(crate) fn create_pointer_type( | ||
&self, | ||
pointee_type: &'ll Metadata, | ||
size: Size, | ||
align: Align, | ||
name: &str, | ||
) -> &'ll Metadata { | ||
unsafe { | ||
llvm::LLVMDIBuilderCreatePointerType( | ||
self, | ||
pointee_type, | ||
size.bits(), | ||
align.bits() as u32, | ||
0, // ("DWARF address space"; default is 0) | ||
name.as_ptr(), | ||
name.len(), | ||
) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is where all the action is, then, since this makes-safe a few things...