File tree Expand file tree Collapse file tree 4 files changed +9
-7
lines changed
compiler/rustc_codegen_llvm/src Expand file tree Collapse file tree 4 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -1182,7 +1182,7 @@ fn create_msvc_imps(
11821182 . filter_map ( |val| {
11831183 // Exclude some symbols that we know are not Rust symbols.
11841184 let name = llvm:: get_value_name ( val) ;
1185- if ignored ( name) { None } else { Some ( ( val, name) ) }
1185+ if ignored ( & name) { None } else { Some ( ( val, name) ) }
11861186 } )
11871187 . map ( move |( val, name) | {
11881188 let mut imp_name = prefix. as_bytes ( ) . to_vec ( ) ;
Original file line number Diff line number Diff line change @@ -306,7 +306,7 @@ fn generate_enzyme_call<'ll>(
306306 // add outer_fn name to ad_name to make it unique, in case users apply autodiff to multiple
307307 // functions. Unwrap will only panic, if LLVM gave us an invalid string.
308308 let name = llvm:: get_value_name ( outer_fn) ;
309- let outer_fn_name = std:: str:: from_utf8 ( name) . unwrap ( ) ;
309+ let outer_fn_name = std:: str:: from_utf8 ( & name) . unwrap ( ) ;
310310 ad_name. push_str ( outer_fn_name) ;
311311
312312 // Let us assume the user wrote the following function square:
Original file line number Diff line number Diff line change @@ -429,7 +429,7 @@ impl<'ll> CodegenCx<'ll, '_> {
429429 // specific rules on what can be cast. So instead of adding a new way to
430430 // generate static initializers that match the static's type, we picked
431431 // the easier option and retroactively change the type of the static item itself.
432- let name = llvm:: get_value_name ( g) . to_vec ( ) ;
432+ let name = llvm:: get_value_name ( g) ;
433433 llvm:: set_value_name ( g, b"" ) ;
434434
435435 let linkage = llvm:: get_linkage ( g) ;
Original file line number Diff line number Diff line change @@ -211,7 +211,7 @@ pub(crate) fn SetFunctionCallConv(fn_: &Value, cc: CallConv) {
211211// function.
212212// For more details on COMDAT sections see e.g., https://www.airs.com/blog/archives/52
213213pub ( crate ) fn SetUniqueComdat ( llmod : & Module , val : & Value ) {
214- let name_buf = get_value_name ( val) . to_vec ( ) ;
214+ let name_buf = get_value_name ( val) ;
215215 let name =
216216 CString :: from_vec_with_nul ( name_buf) . or_else ( |buf| CString :: new ( buf. into_bytes ( ) ) ) . unwrap ( ) ;
217217 set_comdat ( llmod, val, & name) ;
@@ -319,12 +319,14 @@ pub(crate) fn get_param(llfn: &Value, index: c_uint) -> &Value {
319319 }
320320}
321321
322- /// Safe wrapper for `LLVMGetValueName2` into a byte slice
323- pub ( crate ) fn get_value_name ( value : & Value ) -> & [ u8 ] {
322+ /// Safe wrapper for `LLVMGetValueName2`
323+ /// Needs to allocate the value, because `set_value_name` will invalidate
324+ /// the pointer.
325+ pub ( crate ) fn get_value_name ( value : & Value ) -> Vec < u8 > {
324326 unsafe {
325327 let mut len = 0 ;
326328 let data = LLVMGetValueName2 ( value, & mut len) ;
327- std:: slice:: from_raw_parts ( data. cast ( ) , len)
329+ std:: slice:: from_raw_parts ( data. cast ( ) , len) . to_vec ( )
328330 }
329331}
330332
You can’t perform that action at this time.
0 commit comments