Skip to content

Commit

Permalink
Rollup merge of #45189 - alexcrichton:thinlto-allocators, r=michaelwo…
Browse files Browse the repository at this point in the history
…erister

rustc: Handle `#[no_mangle]` anywhere in a crate

This commit updates the reachability pass of the compiler to seed the local
worklist with `#[no_mangle]`-like items anywhere in a crate, not just those
reachable from public items.

Closes #45165
  • Loading branch information
kennytm committed Oct 12, 2017
2 parents 5d25e1e + c7aa741 commit 44c0a9a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/librustc/middle/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ struct CollectPrivateImplItemsVisitor<'a, 'tcx: 'a> {

impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx> {
fn visit_item(&mut self, item: &hir::Item) {
// Anything which has custom linkage gets thrown on the worklist no
// matter where it is in the crate.
if attr::contains_name(&item.attrs, "linkage") {
self.worklist.push(item.id);
}

// We need only trait impls here, not inherent impls, and only non-exported ones
if let hir::ItemImpl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.node {
if !self.access_levels.is_reachable(item.id) {
Expand Down
19 changes: 19 additions & 0 deletions src/test/run-pass/thin-lto-global-allocator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z thinlto -C codegen-units=2
// min-llvm-version 4.0

#![feature(allocator_api, global_allocator)]

#[global_allocator]
static A: std::heap::System = std::heap::System;

fn main() {}

0 comments on commit 44c0a9a

Please sign in to comment.