22
33use std:: ffi:: CString ;
44
5- use rustc:: hir:: { CodegenFnAttrFlags , CodegenFnAttrs } ;
5+ use rustc:: hir:: CodegenFnAttrFlags ;
66use rustc:: hir:: def_id:: { DefId , LOCAL_CRATE } ;
77use rustc:: session:: Session ;
88use rustc:: session:: config:: { Sanitizer , OptLevel } ;
9- use rustc:: ty:: TyCtxt ;
9+ use rustc:: ty:: { self , TyCtxt } ;
1010use rustc:: ty:: layout:: HasTyCtxt ;
1111use rustc:: ty:: query:: Providers ;
1212use rustc_data_structures:: small_c_str:: SmallCStr ;
@@ -202,11 +202,9 @@ pub(crate) fn default_optimisation_attrs(sess: &Session, llfn: &'ll Value) {
202202pub fn from_fn_attrs (
203203 cx : & CodegenCx < ' ll , ' tcx > ,
204204 llfn : & ' ll Value ,
205- id : Option < DefId > ,
206- abi : Abi ,
205+ instance : ty:: Instance < ' tcx > ,
207206) {
208- let codegen_fn_attrs = id. map ( |id| cx. tcx . codegen_fn_attrs ( id) )
209- . unwrap_or_else ( || CodegenFnAttrs :: new ( ) ) ;
207+ let codegen_fn_attrs = cx. tcx . codegen_fn_attrs ( instance. def_id ( ) ) ;
210208
211209 match codegen_fn_attrs. optimize {
212210 OptimizeAttr :: None => {
@@ -224,6 +222,11 @@ pub fn from_fn_attrs(
224222 }
225223 }
226224
225+ // FIXME(eddyb) consolidate these two `inline` calls (and avoid overwrites).
226+ if instance. def . is_inline ( cx. tcx ) {
227+ inline ( cx, llfn, attributes:: InlineAttr :: Hint ) ;
228+ }
229+
227230 inline ( cx, llfn, codegen_fn_attrs. inline ) ;
228231
229232 // The `uwtable` attribute according to LLVM is:
@@ -276,6 +279,9 @@ pub fn from_fn_attrs(
276279 // Special attribute for allocator functions, which can't unwind.
277280 false
278281 } else {
282+ // FIXME(eddyb) avoid this `Instance::fn_sig` call.
283+ // Perhaps store the relevant information in `FnAbi`?
284+ let abi = instance. fn_sig ( cx. tcx ( ) ) . abi ( ) ;
279285 if abi == Abi :: Rust || abi == Abi :: RustCall {
280286 // Any Rust method (or `extern "Rust" fn` or `extern
281287 // "rust-call" fn`) is explicitly allowed to unwind
@@ -330,16 +336,14 @@ pub fn from_fn_attrs(
330336 // Note that currently the `wasm-import-module` doesn't do anything, but
331337 // eventually LLVM 7 should read this and ferry the appropriate import
332338 // module to the output file.
333- if let Some ( id) = id {
334- if cx. tcx . sess . target . target . arch == "wasm32" {
335- if let Some ( module) = wasm_import_module ( cx. tcx , id) {
336- llvm:: AddFunctionAttrStringValue (
337- llfn,
338- llvm:: AttributePlace :: Function ,
339- const_cstr ! ( "wasm-import-module" ) ,
340- & module,
341- ) ;
342- }
339+ if cx. tcx . sess . target . target . arch == "wasm32" {
340+ if let Some ( module) = wasm_import_module ( cx. tcx , instance. def_id ( ) ) {
341+ llvm:: AddFunctionAttrStringValue (
342+ llfn,
343+ llvm:: AttributePlace :: Function ,
344+ const_cstr ! ( "wasm-import-module" ) ,
345+ & module,
346+ ) ;
343347 }
344348 }
345349}
0 commit comments