diff options
| author | DianQK <dianqk@dianqk.net> | 2023-07-18 22:15:47 +0800 |
|---|---|---|
| committer | DianQK <dianqk@dianqk.net> | 2023-07-18 22:15:47 +0800 |
| commit | cc08749df2613c17c8c2e9d8224a24a24c126423 (patch) | |
| tree | 26f2f5b85d4c03d84204d24899e2e84dd800b5cc /compiler/rustc_codegen_ssa | |
| parent | f0580df0d53d67ad5c7f85756eb9f221566e4fb0 (diff) | |
| download | rust-cc08749df2613c17c8c2e9d8224a24a24c126423.tar.gz rust-cc08749df2613c17c8c2e9d8224a24a24c126423.zip | |
Add the `no-builtins` attribute to functions when `no_builtins` is applied at the crate level.
When `no_builtins` is applied at the crate level, we should add the `no-builtins` attribute to each function to ensure it takes effect in LTO.
Diffstat (limited to 'compiler/rustc_codegen_ssa')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/codegen_attrs.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index d6c23012762..0c7b8a79612 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -1,4 +1,4 @@ -use rustc_ast::{ast, MetaItemKind, NestedMetaItem}; +use rustc_ast::{ast, attr, MetaItemKind, NestedMetaItem}; use rustc_attr::{list_contains_name, InlineAttr, InstructionSetAttr, OptimizeAttr}; use rustc_errors::struct_span_err; use rustc_hir as hir; @@ -60,6 +60,14 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER; } + // When `no_builtins` is applied at the crate level, we should add the + // `no-builtins` attribute to each function to ensure it takes effect in LTO. + let crate_attrs = tcx.hir().attrs(rustc_hir::CRATE_HIR_ID); + let no_builtins = attr::contains_name(crate_attrs, sym::no_builtins); + if no_builtins { + codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_BUILTINS; + } + let supported_target_features = tcx.supported_target_features(LOCAL_CRATE); let mut inline_span = None; |
