1
1
//! Set and unset common attributes on LLVM values.
2
2
3
- use std:: ffi:: CString ;
4
-
5
- use cstr:: cstr;
6
3
use rustc_codegen_ssa:: traits:: * ;
7
- use rustc_data_structures:: small_c_str:: SmallCStr ;
8
4
use rustc_hir:: def_id:: DefId ;
9
5
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
10
6
use rustc_middle:: ty:: { self , TyCtxt } ;
@@ -103,11 +99,11 @@ pub fn frame_pointer_type_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attr
103
99
fp = FramePointer :: Always ;
104
100
}
105
101
let attr_value = match fp {
106
- FramePointer :: Always => cstr ! ( "all" ) ,
107
- FramePointer :: NonLeaf => cstr ! ( "non-leaf" ) ,
102
+ FramePointer :: Always => "all" ,
103
+ FramePointer :: NonLeaf => "non-leaf" ,
108
104
FramePointer :: MayOmit => return None ,
109
105
} ;
110
- Some ( llvm:: CreateAttrStringValue ( cx. llcx , cstr ! ( "frame-pointer" ) , attr_value) )
106
+ Some ( llvm:: CreateAttrStringValue ( cx. llcx , "frame-pointer" , attr_value) )
111
107
}
112
108
113
109
/// Tell LLVM what instrument function to insert.
@@ -119,11 +115,11 @@ fn instrument_function_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribu
119
115
120
116
// The function name varies on platforms.
121
117
// See test/CodeGen/mcount.c in clang.
122
- let mcount_name = CString :: new ( cx. sess ( ) . target . mcount . as_str ( ) . as_bytes ( ) ) . unwrap ( ) ;
118
+ let mcount_name = cx. sess ( ) . target . mcount . as_str ( ) ;
123
119
124
120
Some ( llvm:: CreateAttrStringValue (
125
121
cx. llcx ,
126
- cstr ! ( "instrument-function-entry-inlined" ) ,
122
+ "instrument-function-entry-inlined" ,
127
123
& mcount_name,
128
124
) )
129
125
} else {
@@ -159,20 +155,20 @@ fn probestack_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
159
155
StackProbeType :: None => return None ,
160
156
// Request LLVM to generate the probes inline. If the given LLVM version does not support
161
157
// this, no probe is generated at all (even if the attribute is specified).
162
- StackProbeType :: Inline => cstr ! ( "inline-asm" ) ,
158
+ StackProbeType :: Inline => "inline-asm" ,
163
159
// Flag our internal `__rust_probestack` function as the stack probe symbol.
164
160
// This is defined in the `compiler-builtins` crate for each architecture.
165
- StackProbeType :: Call => cstr ! ( "__rust_probestack" ) ,
161
+ StackProbeType :: Call => "__rust_probestack" ,
166
162
// Pick from the two above based on the LLVM version.
167
163
StackProbeType :: InlineOrCall { min_llvm_version_for_inline } => {
168
164
if llvm_util:: get_version ( ) < min_llvm_version_for_inline {
169
- cstr ! ( "__rust_probestack" )
165
+ "__rust_probestack"
170
166
} else {
171
- cstr ! ( "inline-asm" )
167
+ "inline-asm"
172
168
}
173
169
}
174
170
} ;
175
- Some ( llvm:: CreateAttrStringValue ( cx. llcx , cstr ! ( "probe-stack" ) , attr_value) )
171
+ Some ( llvm:: CreateAttrStringValue ( cx. llcx , "probe-stack" , attr_value) )
176
172
}
177
173
178
174
fn stackprotector_attr < ' ll > ( cx : & CodegenCx < ' ll , ' _ > ) -> Option < & ' ll Attribute > {
@@ -187,15 +183,13 @@ fn stackprotector_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
187
183
}
188
184
189
185
pub fn target_cpu_attr < ' ll > ( cx : & CodegenCx < ' ll , ' _ > ) -> & ' ll Attribute {
190
- let target_cpu = SmallCStr :: new ( llvm_util:: target_cpu ( cx. tcx . sess ) ) ;
191
- llvm:: CreateAttrStringValue ( cx. llcx , cstr ! ( "target-cpu" ) , target_cpu. as_c_str ( ) )
186
+ let target_cpu = llvm_util:: target_cpu ( cx. tcx . sess ) ;
187
+ llvm:: CreateAttrStringValue ( cx. llcx , "target-cpu" , target_cpu)
192
188
}
193
189
194
190
pub fn tune_cpu_attr < ' ll > ( cx : & CodegenCx < ' ll , ' _ > ) -> Option < & ' ll Attribute > {
195
- llvm_util:: tune_cpu ( cx. tcx . sess ) . map ( |tune| {
196
- let tune_cpu = SmallCStr :: new ( tune) ;
197
- llvm:: CreateAttrStringValue ( cx. llcx , cstr ! ( "tune-cpu" ) , tune_cpu. as_c_str ( ) )
198
- } )
191
+ llvm_util:: tune_cpu ( cx. tcx . sess )
192
+ . map ( |tune_cpu| llvm:: CreateAttrStringValue ( cx. llcx , "tune-cpu" , tune_cpu) )
199
193
}
200
194
201
195
/// Get the `NonLazyBind` LLVM attribute,
@@ -280,7 +274,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
280
274
}
281
275
282
276
if cx. sess ( ) . opts . debugging_opts . profile_sample_use . is_some ( ) {
283
- to_add. push ( llvm:: CreateAttrString ( cx. llcx , cstr ! ( "use-sample-profile" ) ) ) ;
277
+ to_add. push ( llvm:: CreateAttrString ( cx. llcx , "use-sample-profile" ) ) ;
284
278
}
285
279
286
280
// FIXME: none of these three functions interact with source level attributes.
@@ -310,7 +304,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
310
304
attributes:: apply_to_llfn ( llfn, AttributePlace :: ReturnValue , & [ no_alias] ) ;
311
305
}
312
306
if codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: CMSE_NONSECURE_ENTRY ) {
313
- to_add. push ( llvm:: CreateAttrString ( cx. llcx , cstr ! ( "cmse_nonsecure_entry" ) ) ) ;
307
+ to_add. push ( llvm:: CreateAttrString ( cx. llcx , "cmse_nonsecure_entry" ) ) ;
314
308
}
315
309
if let Some ( align) = codegen_fn_attrs. alignment {
316
310
llvm:: set_alignment ( llfn, align as usize ) ;
@@ -363,12 +357,12 @@ pub fn from_fn_attrs<'ll, 'tcx>(
363
357
// If this function is an import from the environment but the wasm
364
358
// import has a specific module/name, apply them here.
365
359
if let Some ( module) = wasm_import_module ( cx. tcx , instance. def_id ( ) ) {
366
- to_add. push ( llvm:: CreateAttrStringValue ( cx. llcx , cstr ! ( "wasm-import-module" ) , & module) ) ;
360
+ to_add. push ( llvm:: CreateAttrStringValue ( cx. llcx , "wasm-import-module" , & module) ) ;
367
361
368
362
let name =
369
363
codegen_fn_attrs. link_name . unwrap_or_else ( || cx. tcx . item_name ( instance. def_id ( ) ) ) ;
370
- let name = CString :: new ( name. as_str ( ) ) . unwrap ( ) ;
371
- to_add. push ( llvm:: CreateAttrStringValue ( cx. llcx , cstr ! ( "wasm-import-name" ) , & name) ) ;
364
+ let name = name. as_str ( ) ;
365
+ to_add. push ( llvm:: CreateAttrStringValue ( cx. llcx , "wasm-import-name" , name) ) ;
372
366
}
373
367
374
368
// The `"wasm"` abi on wasm targets automatically enables the
@@ -388,13 +382,13 @@ pub fn from_fn_attrs<'ll, 'tcx>(
388
382
let val = global_features
389
383
. chain ( function_features. iter ( ) . map ( |s| & s[ ..] ) )
390
384
. intersperse ( "," )
391
- . collect :: < SmallCStr > ( ) ;
392
- to_add. push ( llvm:: CreateAttrStringValue ( cx. llcx , cstr ! ( "target-features" ) , & val) ) ;
385
+ . collect :: < String > ( ) ;
386
+ to_add. push ( llvm:: CreateAttrStringValue ( cx. llcx , "target-features" , & val) ) ;
393
387
}
394
388
395
389
attributes:: apply_to_llfn ( llfn, Function , & to_add) ;
396
390
}
397
391
398
- fn wasm_import_module ( tcx : TyCtxt < ' _ > , id : DefId ) -> Option < CString > {
399
- tcx. wasm_import_module_map ( id. krate ) . get ( & id) . map ( |s| CString :: new ( & s [ .. ] ) . unwrap ( ) )
392
+ fn wasm_import_module ( tcx : TyCtxt < ' _ > , id : DefId ) -> Option < & String > {
393
+ tcx. wasm_import_module_map ( id. krate ) . get ( & id)
400
394
}
0 commit comments