diff options
| author | bors <bors@rust-lang.org> | 2022-03-04 10:38:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-03-04 10:38:11 +0000 |
| commit | 047f9c4bc4e26df4f54c3c76af3e963782ed05e4 (patch) | |
| tree | 38f0265287eb1fd99c918a06ee788ba01bc16bf7 /compiler/rustc_codegen_llvm/src/llvm/mod.rs | |
| parent | 62ff2bcf9485f52050093d1780f409d50953549b (diff) | |
| parent | 926bf1a3718fc408b2d75a7536b7a2ed3d2d070b (diff) | |
| download | rust-047f9c4bc4e26df4f54c3c76af3e963782ed05e4.tar.gz rust-047f9c4bc4e26df4f54c3c76af3e963782ed05e4.zip | |
Auto merge of #94539 - tmiasko:string-attributes, r=nikic
Pass LLVM string attributes as string slices
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/llvm/mod.rs')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/llvm/mod.rs | 24 |
1 files changed, 20 insertions, 4 deletions
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 { |
