@@ -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;
@@ -1079,11 +1081,35 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
1079
1081
1080
1082
fn get_val(bcx: block, did: ast::def_id, const_ty: ty::t)
1081
1083
-> 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
+ }
1087
1113
}
1088
1114
1089
1115
let did = get_did(ccx, did);
0 commit comments