diff options
| author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2022-03-03 00:00:00 +0000 |
|---|---|---|
| committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2022-03-03 00:28:50 +0100 |
| commit | 926bf1a3718fc408b2d75a7536b7a2ed3d2d070b (patch) | |
| tree | 524c12d755ea38356df8ddac19baa8d3856c313e /compiler/rustc_codegen_llvm/src/llvm | |
| parent | 08504c64aa7c4163a51c1982ed10075bb89cec0e (diff) | |
| download | rust-926bf1a3718fc408b2d75a7536b7a2ed3d2d070b.tar.gz rust-926bf1a3718fc408b2d75a7536b7a2ed3d2d070b.zip | |
Pass LLVM string attributes as string slices
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/llvm')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/llvm/mod.rs | 24 |
2 files changed, 23 insertions, 6 deletions
diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 4a8894983b9..6c944b9e486 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -1175,11 +1175,12 @@ extern "C" { // Operations on attributes pub fn LLVMRustCreateAttrNoValue(C: &Context, attr: AttributeKind) -> &Attribute; - pub fn LLVMRustCreateAttrString(C: &Context, Name: *const c_char) -> &Attribute; - pub fn LLVMRustCreateAttrStringValue( + pub fn LLVMCreateStringAttribute( C: &Context, Name: *const c_char, + NameLen: c_uint, Value: *const c_char, + ValueLen: c_uint, ) -> &Attribute; pub fn LLVMRustCreateAlignmentAttr(C: &Context, bytes: u64) -> &Attribute; pub fn LLVMRustCreateDereferenceableAttr(C: &Context, bytes: u64) -> &Attribute; diff --git a/compiler/rustc_codegen_llvm/src/llvm/mod.rs b/compiler/rustc_codegen_llvm/src/llvm/mod.rs index 4892b8d4a84..48fbc1de8ee 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/mod.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/mod.rs @@ -47,12 +47,28 @@ pub fn AddCallSiteAttributes<'ll>( } } -pub fn CreateAttrStringValue<'ll>(llcx: &'ll Context, attr: &CStr, value: &CStr) -> &'ll Attribute { - unsafe { LLVMRustCreateAttrStringValue(llcx, attr.as_ptr(), value.as_ptr()) } +pub fn CreateAttrStringValue<'ll>(llcx: &'ll Context, attr: &str, value: &str) -> &'ll Attribute { + unsafe { + LLVMCreateStringAttribute( + llcx, + attr.as_ptr().cast(), + attr.len().try_into().unwrap(), + value.as_ptr().cast(), + value.len().try_into().unwrap(), + ) + } } -pub fn CreateAttrString<'ll>(llcx: &'ll Context, attr: &CStr) -> &'ll Attribute { - unsafe { LLVMRustCreateAttrStringValue(llcx, attr.as_ptr(), std::ptr::null()) } +pub fn CreateAttrString<'ll>(llcx: &'ll Context, attr: &str) -> &'ll Attribute { + unsafe { + LLVMCreateStringAttribute( + llcx, + attr.as_ptr().cast(), + attr.len().try_into().unwrap(), + std::ptr::null(), + 0, + ) + } } pub fn CreateAlignmentAttr(llcx: &Context, bytes: u64) -> &Attribute { |
