diff options
| author | bors <bors@rust-lang.org> | 2024-10-20 03:34:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-10-20 03:34:09 +0000 |
| commit | d68c32779627fcd72a928c9e89f65094dbcf7482 (patch) | |
| tree | f664187b0159d5a2466b5ccb27d5dde7d906c24e /compiler/rustc_codegen_llvm/src/llvm/mod.rs | |
| parent | 54791efd8235805dcfbdad3b8788e08f2142c50b (diff) | |
| parent | 456821be88146f2f94be26354576794b431fd83e (diff) | |
| download | rust-d68c32779627fcd72a928c9e89f65094dbcf7482.tar.gz rust-d68c32779627fcd72a928c9e89f65094dbcf7482.zip | |
Auto merge of #131958 - Zalathar:rollup-gkuk3n1, r=Zalathar
Rollup of 4 pull requests Successful merges: - #131876 (compiler: Use LLVM's Comdat support) - #131941 (compiletest: disambiguate html-tidy from rust tidy tool) - #131942 (compiler: Adopt rust-analyzer impls for `LayoutCalculatorError`) - #131945 (rustdoc: Clean up footnote handling) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/llvm/mod.rs')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/llvm/mod.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/compiler/rustc_codegen_llvm/src/llvm/mod.rs b/compiler/rustc_codegen_llvm/src/llvm/mod.rs index d0db350a149..b306396e15a 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/mod.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/mod.rs @@ -178,10 +178,10 @@ pub fn SetFunctionCallConv(fn_: &Value, cc: CallConv) { // function. // For more details on COMDAT sections see e.g., https://www.airs.com/blog/archives/52 pub fn SetUniqueComdat(llmod: &Module, val: &Value) { - unsafe { - let name = get_value_name(val); - LLVMRustSetComdat(llmod, val, name.as_ptr().cast(), name.len()); - } + let name_buf = get_value_name(val).to_vec(); + let name = + CString::from_vec_with_nul(name_buf).or_else(|buf| CString::new(buf.into_bytes())).unwrap(); + set_comdat(llmod, val, &name); } pub fn SetUnnamedAddress(global: &Value, unnamed: UnnamedAddr) { @@ -217,8 +217,7 @@ pub fn set_section(llglobal: &Value, section_name: &str) { } } -pub fn add_global<'a>(llmod: &'a Module, ty: &'a Type, name: &str) -> &'a Value { - let name_cstr = CString::new(name).expect("unexpected CString error"); +pub fn add_global<'a>(llmod: &'a Module, ty: &'a Type, name_cstr: &CStr) -> &'a Value { unsafe { LLVMAddGlobal(llmod, ty, name_cstr.as_ptr()) } } @@ -252,9 +251,14 @@ pub fn set_alignment(llglobal: &Value, align: Align) { } } -pub fn set_comdat(llmod: &Module, llglobal: &Value, name: &str) { +/// Get the `name`d comdat from `llmod` and assign it to `llglobal`. +/// +/// Inserts the comdat into `llmod` if it does not exist. +/// It is an error to call this if the target does not support comdat. +pub fn set_comdat(llmod: &Module, llglobal: &Value, name: &CStr) { unsafe { - LLVMRustSetComdat(llmod, llglobal, name.as_ptr().cast(), name.len()); + let comdat = LLVMGetOrInsertComdat(llmod, name.as_ptr()); + LLVMSetComdat(llglobal, comdat); } } |
