@@ -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;
@@ -1079,11 +1081,35 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
10791081
10801082 fn get_val(bcx: block, did: ast::def_id, const_ty: ty::t)
10811083 -> ValueRef {
1082- // The LLVM global has the type of its initializer,
1083- // which may not be equal to the enum's type for
1084- // non-C-like enums.
1085- PointerCast(bcx, base::get_item_val(bcx.ccx(), did.node),
1086- T_ptr(type_of(bcx.ccx(), const_ty)))
1084+ if did.crate == ast::local_crate {
1085+ // The LLVM global has the type of its initializer,
1086+ // which may not be equal to the enum's type for
1087+ // non-C-like enums.
1088+ PointerCast(bcx,
1089+ base::get_item_val(bcx.ccx(), did.node),
1090+ T_ptr(type_of(bcx.ccx(), const_ty)))
1091+ } else {
1092+ // For external constants, we don't inline.
1093+ match bcx.ccx().extern_const_values.find(&did) {
1094+ None => {
1095+ unsafe {
1096+ let llty = type_of(bcx.ccx(), const_ty);
1097+ let symbol = csearch::get_symbol(
1098+ bcx.ccx().sess.cstore,
1099+ did);
1100+ let llval = llvm::LLVMAddGlobal(
1101+ bcx.ccx().llmod,
1102+ llty,
1103+ transmute::<&u8,*i8>(&symbol[0]));
1104+ bcx.ccx().extern_const_values.insert(
1105+ did,
1106+ llval);
1107+ llval
1108+ }
1109+ }
1110+ Some(llval) => *llval
1111+ }
1112+ }
10871113 }
10881114
10891115 let did = get_did(ccx, did);
0 commit comments