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(
1182
1182
. filter_map ( |val| {
1183
1183
// Exclude some symbols that we know are not Rust symbols.
1184
1184
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) ) }
1186
1186
} )
1187
1187
. map ( move |( val, name) | {
1188
1188
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>(
306
306
// add outer_fn name to ad_name to make it unique, in case users apply autodiff to multiple
307
307
// functions. Unwrap will only panic, if LLVM gave us an invalid string.
308
308
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 ( ) ;
310
310
ad_name. push_str ( outer_fn_name) ;
311
311
312
312
// 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, '_> {
429
429
// specific rules on what can be cast. So instead of adding a new way to
430
430
// generate static initializers that match the static's type, we picked
431
431
// 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) ;
433
433
llvm:: set_value_name ( g, b"" ) ;
434
434
435
435
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) {
211
211
// function.
212
212
// For more details on COMDAT sections see e.g., https://www.airs.com/blog/archives/52
213
213
pub ( 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) ;
215
215
let name =
216
216
CString :: from_vec_with_nul ( name_buf) . or_else ( |buf| CString :: new ( buf. into_bytes ( ) ) ) . unwrap ( ) ;
217
217
set_comdat ( llmod, val, & name) ;
@@ -319,12 +319,14 @@ pub(crate) fn get_param(llfn: &Value, index: c_uint) -> &Value {
319
319
}
320
320
}
321
321
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 > {
324
326
unsafe {
325
327
let mut len = 0 ;
326
328
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 ( )
328
330
}
329
331
}
330
332
You can’t perform that action at this time.
0 commit comments