1
Fork 0

Fix reachable_set for non-function items in non-library crates

This commit is contained in:
hyd-dev 2021-08-14 23:24:33 +08:00
parent 9315a0cd4c
commit 29b73ee5fa
No known key found for this signature in database
GPG key ID: 74FA7FD5B8DA14B8
2 changed files with 19 additions and 17 deletions

View file

@ -211,21 +211,22 @@ impl<'tcx> ReachableContext<'tcx> {
if !self.any_library { if !self.any_library {
// If we are building an executable, only explicitly extern // If we are building an executable, only explicitly extern
// types need to be exported. // types need to be exported.
if let Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, ..), def_id, .. }) let reachable =
| Node::ImplItem(hir::ImplItem { if let Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, ..), .. })
kind: hir::ImplItemKind::Fn(sig, ..), | Node::ImplItem(hir::ImplItem {
def_id, kind: hir::ImplItemKind::Fn(sig, ..), ..
.. }) = *node
}) = *node {
{ sig.header.abi != Abi::Rust
let reachable = sig.header.abi != Abi::Rust; } else {
let codegen_attrs = self.tcx.codegen_fn_attrs(*def_id); false
let is_extern = codegen_attrs.contains_extern_indicator(); };
let std_internal = let codegen_attrs = self.tcx.codegen_fn_attrs(search_item);
codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL); let is_extern = codegen_attrs.contains_extern_indicator();
if reachable || is_extern || std_internal { let std_internal =
self.reachable_symbols.insert(search_item); codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL);
} if reachable || is_extern || std_internal {
self.reachable_symbols.insert(search_item);
} }
} else { } else {
// If we are building a library, then reachable symbols will // If we are building a library, then reachable symbols will

View file

@ -1,10 +1,11 @@
// revisions: lib staticlib
// ignore-emscripten default visibility is hidden // ignore-emscripten default visibility is hidden
// compile-flags: -O // compile-flags: -O
// `#[no_mangle]`d static variables always have external linkage, i.e., no `internal` in their // `#[no_mangle]`d static variables always have external linkage, i.e., no `internal` in their
// definitions // definitions
#![crate_type = "lib"] #![cfg_attr(lib, crate_type = "lib")]
#![no_std] #![cfg_attr(staticlib, crate_type = "staticlib")]
// CHECK: @A = local_unnamed_addr constant // CHECK: @A = local_unnamed_addr constant
#[no_mangle] #[no_mangle]