@@ -124,6 +124,7 @@ use core::prelude::*;
124
124
use back:: abi;
125
125
use lib;
126
126
use lib:: llvm:: { ValueRef , TypeRef , llvm, True } ;
127
+ use metadata:: csearch;
127
128
use middle:: borrowck:: root_map_key;
128
129
use middle:: trans:: _match;
129
130
use middle:: trans:: adt;
@@ -150,6 +151,7 @@ use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowVecRef, AutoBorrowFn,
150
151
use util:: common:: indenter;
151
152
use util:: ppaux:: ty_to_str;
152
153
154
+ use core:: cast:: transmute;
153
155
use core:: hashmap:: linear:: LinearMap ;
154
156
use syntax:: print:: pprust:: { expr_to_str} ;
155
157
use syntax:: ast;
@@ -1096,11 +1098,35 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
1096
1098
1097
1099
fn get_val(bcx: block, did: ast::def_id, const_ty: ty::t)
1098
1100
-> ValueRef {
1099
- // The LLVM global has the type of its initializer,
1100
- // which may not be equal to the enum's type for
1101
- // non-C-like enums.
1102
- PointerCast(bcx, base::get_item_val(bcx.ccx(), did.node),
1103
- T_ptr(type_of(bcx.ccx(), const_ty)))
1101
+ if did.crate == ast::local_crate {
1102
+ // The LLVM global has the type of its initializer,
1103
+ // which may not be equal to the enum's type for
1104
+ // non-C-like enums.
1105
+ PointerCast(bcx,
1106
+ base::get_item_val(bcx.ccx(), did.node),
1107
+ T_ptr(type_of(bcx.ccx(), const_ty)))
1108
+ } else {
1109
+ // For external constants, we don't inline.
1110
+ match bcx.ccx().extern_const_values.find(&did) {
1111
+ None => {
1112
+ unsafe {
1113
+ let llty = type_of(bcx.ccx(), const_ty);
1114
+ let symbol = csearch::get_symbol(
1115
+ bcx.ccx().sess.cstore,
1116
+ did);
1117
+ let llval = llvm::LLVMAddGlobal(
1118
+ bcx.ccx().llmod,
1119
+ llty,
1120
+ transmute::<&u8,*i8>(&symbol[0]));
1121
+ bcx.ccx().extern_const_values.insert(
1122
+ did,
1123
+ llval);
1124
+ llval
1125
+ }
1126
+ }
1127
+ Some(llval) => *llval
1128
+ }
1129
+ }
1104
1130
}
1105
1131
1106
1132
let did = get_did(ccx, did);
0 commit comments