11//! Set and unset common attributes on LLVM values.
22
3- use std:: ffi:: CString ;
4-
5- use cstr:: cstr;
63use rustc_codegen_ssa:: traits:: * ;
7- use rustc_data_structures:: small_c_str:: SmallCStr ;
84use rustc_hir:: def_id:: DefId ;
95use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
106use rustc_middle:: ty:: { self , TyCtxt } ;
@@ -103,11 +99,11 @@ pub fn frame_pointer_type_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attr
10399 fp = FramePointer :: Always ;
104100 }
105101 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" ,
108104 FramePointer :: MayOmit => return None ,
109105 } ;
110- Some ( llvm:: CreateAttrStringValue ( cx. llcx , cstr ! ( "frame-pointer" ) , attr_value) )
106+ Some ( llvm:: CreateAttrStringValue ( cx. llcx , "frame-pointer" , attr_value) )
111107}
112108
113109/// Tell LLVM what instrument function to insert.
@@ -119,11 +115,11 @@ fn instrument_function_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribu
119115
120116 // The function name varies on platforms.
121117 // 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 ( ) ;
123119
124120 Some ( llvm:: CreateAttrStringValue (
125121 cx. llcx ,
126- cstr ! ( "instrument-function-entry-inlined" ) ,
122+ "instrument-function-entry-inlined" ,
127123 & mcount_name,
128124 ) )
129125 } else {
@@ -159,20 +155,20 @@ fn probestack_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
159155 StackProbeType :: None => return None ,
160156 // Request LLVM to generate the probes inline. If the given LLVM version does not support
161157 // this, no probe is generated at all (even if the attribute is specified).
162- StackProbeType :: Inline => cstr ! ( "inline-asm" ) ,
158+ StackProbeType :: Inline => "inline-asm" ,
163159 // Flag our internal `__rust_probestack` function as the stack probe symbol.
164160 // This is defined in the `compiler-builtins` crate for each architecture.
165- StackProbeType :: Call => cstr ! ( "__rust_probestack" ) ,
161+ StackProbeType :: Call => "__rust_probestack" ,
166162 // Pick from the two above based on the LLVM version.
167163 StackProbeType :: InlineOrCall { min_llvm_version_for_inline } => {
168164 if llvm_util:: get_version ( ) < min_llvm_version_for_inline {
169- cstr ! ( "__rust_probestack" )
165+ "__rust_probestack"
170166 } else {
171- cstr ! ( "inline-asm" )
167+ "inline-asm"
172168 }
173169 }
174170 } ;
175- Some ( llvm:: CreateAttrStringValue ( cx. llcx , cstr ! ( "probe-stack" ) , attr_value) )
171+ Some ( llvm:: CreateAttrStringValue ( cx. llcx , "probe-stack" , attr_value) )
176172}
177173
178174fn stackprotector_attr < ' ll > ( cx : & CodegenCx < ' ll , ' _ > ) -> Option < & ' ll Attribute > {
@@ -187,15 +183,13 @@ fn stackprotector_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
187183}
188184
189185pub 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)
192188}
193189
194190pub 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) )
199193}
200194
201195/// Get the `NonLazyBind` LLVM attribute,
@@ -280,7 +274,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
280274 }
281275
282276 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" ) ) ;
284278 }
285279
286280 // FIXME: none of these three functions interact with source level attributes.
@@ -310,7 +304,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
310304 attributes:: apply_to_llfn ( llfn, AttributePlace :: ReturnValue , & [ no_alias] ) ;
311305 }
312306 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" ) ) ;
314308 }
315309 if let Some ( align) = codegen_fn_attrs. alignment {
316310 llvm:: set_alignment ( llfn, align as usize ) ;
@@ -363,12 +357,12 @@ pub fn from_fn_attrs<'ll, 'tcx>(
363357 // If this function is an import from the environment but the wasm
364358 // import has a specific module/name, apply them here.
365359 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) ) ;
367361
368362 let name =
369363 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) ) ;
372366 }
373367
374368 // The `"wasm"` abi on wasm targets automatically enables the
@@ -388,13 +382,13 @@ pub fn from_fn_attrs<'ll, 'tcx>(
388382 let val = global_features
389383 . chain ( function_features. iter ( ) . map ( |s| & s[ ..] ) )
390384 . 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) ) ;
393387 }
394388
395389 attributes:: apply_to_llfn ( llfn, Function , & to_add) ;
396390}
397391
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)
400394}
0 commit comments