Skip to content

Commit 0d76a47

Browse files
committed
---
yaml --- r: 80561 b: refs/heads/master c: 0efc482 h: refs/heads/master i: 80559: 215770d v: v3
1 parent 46544ed commit 0d76a47

File tree

5 files changed

+68
-6
lines changed

5 files changed

+68
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: c135cb268355afe77d2ce0313a8d3e20a4e2fdd3
2+
refs/heads/master: 0efc4822e93221714aa7d142de44a057bdbad2ca
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cbd1eefbd350797b783df119fed7956d7e1c74ad
55
refs/heads/try: 71bebebc37fbb229877da88dde13c2f35913bd77

trunk/src/librustc/middle/trans/base.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,10 +2559,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
25592559
// LLVM type is not fully determined by the Rust type.
25602560
let (v, inlineable) = consts::const_expr(ccx, expr);
25612561
ccx.const_values.insert(id, v);
2562-
if !inlineable {
2563-
debug!("%s not inlined", sym);
2564-
ccx.non_inlineable_statics.insert(id);
2565-
}
2562+
let mut inlineable = inlineable;
25662563
exprt = true;
25672564

25682565
unsafe {
@@ -2578,8 +2575,30 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
25782575
lib::llvm::SetUnnamedAddr(g, true);
25792576
lib::llvm::SetLinkage(g,
25802577
lib::llvm::InternalLinkage);
2578+
2579+
// This is a curious case where we must make
2580+
// all of these statics inlineable. If a
2581+
// global is tagged as
2582+
// address_insignificant, then LLVM won't
2583+
// coalesce globals unless they have an
2584+
// internal linkage type. This means that
2585+
// external crates cannot use this global.
2586+
// This is a problem for things like inner
2587+
// statics in generic functions, because the
2588+
// function will be inlined into another
2589+
// crate and then attempt to link to the
2590+
// static in the original crate, only to
2591+
// find that it's not there. On the other
2592+
// side of inlininig, the crates knows to
2593+
// not declare this static as
2594+
// available_externally (because it isn't)
2595+
inlineable = true;
25812596
}
25822597

2598+
if !inlineable {
2599+
debug!("%s not inlined", sym);
2600+
ccx.non_inlineable_statics.insert(id);
2601+
}
25832602
ccx.item_symbols.insert(i.id, sym);
25842603
g
25852604
}

trunk/src/librustc/middle/trans/inline.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::vec;
2121
use syntax::ast;
2222
use syntax::ast_map::path_name;
2323
use syntax::ast_util::local_def;
24+
use syntax::attr;
2425

2526
pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId)
2627
-> ast::DefId {
@@ -68,7 +69,12 @@ pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId)
6869
match item.node {
6970
ast::item_static(*) => {
7071
let g = get_item_val(ccx, item.id);
71-
SetLinkage(g, AvailableExternallyLinkage);
72+
// see the comment in get_item_val() as to why this check is
73+
// performed here.
74+
if !attr::contains_name(item.attrs,
75+
"address_insignificant") {
76+
SetLinkage(g, AvailableExternallyLinkage);
77+
}
7278
}
7379
_ => {}
7480
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub fn foo<T>() -> int {
12+
#[address_insignificant]
13+
static a: int = 3;
14+
a
15+
}
16+
17+
pub fn bar() -> int {
18+
foo::<int>()
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-fast windows doesn't like aux-build
12+
// aux-build:xcrate_address_insignificant.rs
13+
14+
extern mod foo(name = "xcrate_address_insignificant");
15+
16+
fn main() {
17+
assert_eq!(foo::foo::<float>(), foo::bar());
18+
}

0 commit comments

Comments
 (0)