2
2
3
3
use std:: ffi:: CString ;
4
4
5
- use rustc:: hir:: { CodegenFnAttrFlags , CodegenFnAttrs } ;
5
+ use rustc:: hir:: CodegenFnAttrFlags ;
6
6
use rustc:: hir:: def_id:: { DefId , LOCAL_CRATE } ;
7
7
use rustc:: session:: Session ;
8
8
use rustc:: session:: config:: { Sanitizer , OptLevel } ;
9
- use rustc:: ty:: TyCtxt ;
9
+ use rustc:: ty:: { self , TyCtxt } ;
10
10
use rustc:: ty:: layout:: HasTyCtxt ;
11
11
use rustc:: ty:: query:: Providers ;
12
12
use rustc_data_structures:: small_c_str:: SmallCStr ;
@@ -202,11 +202,9 @@ pub(crate) fn default_optimisation_attrs(sess: &Session, llfn: &'ll Value) {
202
202
pub fn from_fn_attrs (
203
203
cx : & CodegenCx < ' ll , ' tcx > ,
204
204
llfn : & ' ll Value ,
205
- id : Option < DefId > ,
206
- abi : Abi ,
205
+ instance : ty:: Instance < ' tcx > ,
207
206
) {
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 ( ) ) ;
210
208
211
209
match codegen_fn_attrs. optimize {
212
210
OptimizeAttr :: None => {
@@ -224,6 +222,11 @@ pub fn from_fn_attrs(
224
222
}
225
223
}
226
224
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
+
227
230
inline ( cx, llfn, codegen_fn_attrs. inline ) ;
228
231
229
232
// The `uwtable` attribute according to LLVM is:
@@ -276,6 +279,9 @@ pub fn from_fn_attrs(
276
279
// Special attribute for allocator functions, which can't unwind.
277
280
false
278
281
} 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 ( ) ;
279
285
if abi == Abi :: Rust || abi == Abi :: RustCall {
280
286
// Any Rust method (or `extern "Rust" fn` or `extern
281
287
// "rust-call" fn`) is explicitly allowed to unwind
@@ -330,16 +336,14 @@ pub fn from_fn_attrs(
330
336
// Note that currently the `wasm-import-module` doesn't do anything, but
331
337
// eventually LLVM 7 should read this and ferry the appropriate import
332
338
// 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
+ ) ;
343
347
}
344
348
}
345
349
}
0 commit comments