@@ -124,6 +124,7 @@ use core::prelude::*;
124124use back:: abi;
125125use lib;
126126use lib:: llvm:: { ValueRef , TypeRef , llvm, True } ;
127+ use metadata:: csearch;
127128use middle:: borrowck:: root_map_key;
128129use middle:: trans:: _match;
129130use middle:: trans:: adt;
@@ -150,6 +151,7 @@ use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowVecRef, AutoBorrowFn,
150151use util:: common:: indenter;
151152use util:: ppaux:: ty_to_str;
152153
154+ use core:: cast:: transmute;
153155use core:: hashmap:: linear:: LinearMap ;
154156use syntax:: print:: pprust:: { expr_to_str} ;
155157use syntax:: ast;
@@ -1096,11 +1098,35 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
10961098
10971099 fn get_val(bcx: block, did: ast::def_id, const_ty: ty::t)
10981100 -> 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+ }
11041130 }
11051131
11061132 let did = get_did(ccx, did);
0 commit comments