diff options
| author | Levi Zim <rsworktech@outlook.com> | 2024-04-09 14:47:06 +0800 |
|---|---|---|
| committer | kxxt <rsworktech@outlook.com> | 2024-04-09 08:53:11 +0200 |
| commit | 33db20978e8157f53ca24fce1c54a7b5e07159cf (patch) | |
| tree | b6b95f1a3a4692b55f5c3b985664c9007dda2772 /compiler/rustc_codegen_llvm/src | |
| parent | adec1a2e84ba61356e6651f277e72452254699a4 (diff) | |
| download | rust-33db20978e8157f53ca24fce1c54a7b5e07159cf.tar.gz rust-33db20978e8157f53ca24fce1c54a7b5e07159cf.zip | |
Pass value and valueLen to create a StringRef
Instead of creating a cstring. Co-authored-by: LoveSy <shana@zju.edu.cn>
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/context.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 1 |
2 files changed, 6 insertions, 7 deletions
diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index c31bc669f4d..d32baa6dc02 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -35,7 +35,6 @@ use libc::c_uint; use std::borrow::Borrow; use std::cell::{Cell, RefCell}; use std::ffi::CStr; -use std::ffi::CString; use std::str; /// There is one `CodegenCx` per compilation unit. Each one has its own LLVM @@ -332,15 +331,14 @@ pub unsafe fn create_module<'ll>( // correctly setting target-abi for the LTO object // FIXME: https://github.com/llvm/llvm-project/issues/50591 // If llvm_abiname is empty, emit nothing. - if matches!(sess.target.arch.as_ref(), "riscv32" | "riscv64") - && !sess.target.options.llvm_abiname.is_empty() - { - let llvm_abiname = CString::new(sess.target.options.llvm_abiname.as_ref()).unwrap(); + let llvm_abiname = &sess.target.options.llvm_abiname; + if matches!(sess.target.arch.as_ref(), "riscv32" | "riscv64") && !llvm_abiname.is_empty() { llvm::LLVMRustAddModuleFlagString( llmod, llvm::LLVMModFlagBehavior::Error, - c"target-abi".as_ptr() as *const _, - llvm_abiname.as_ptr() as *const _, + c"target-abi".as_ptr(), + llvm_abiname.as_ptr().cast(), + llvm_abiname.len(), ); } diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 7aa9a9547dc..5509baaa3e9 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -1813,6 +1813,7 @@ extern "C" { merge_behavior: LLVMModFlagBehavior, name: *const c_char, value: *const c_char, + value_len: size_t, ); pub fn LLVMRustHasModuleFlag(M: &Module, name: *const c_char, len: size_t) -> bool; |
