@@ -5277,19 +5277,12 @@ fn trans_const(@crate_ctxt cx, @ast.expr e,
5277
5277
& ast. def_id cid, & ast. ann ann) {
5278
5278
auto t = node_ann_type( cx, ann) ;
5279
5279
auto v = trans_const_expr( cx, e) ;
5280
- if ( ty. type_is_scalar( t) ) {
5281
- // The scalars come back as 1st class LLVM vals
5282
- // which we have to stick into global constants.
5283
- auto g = llvm. LLVMAddGlobal ( cx. llmod, val_ty( v) ,
5284
- _str. buf( cx. names. next( cx. path) ) ) ;
5285
- llvm. LLVMSetInitializer ( g, v) ;
5286
- llvm. LLVMSetGlobalConstant ( g, True ) ;
5287
- llvm. LLVMSetLinkage ( g, lib. llvm. LLVMPrivateLinkage
5288
- as llvm. Linkage ) ;
5289
- cx. consts. insert( cid, g) ;
5290
- } else {
5291
- cx. consts. insert( cid, v) ;
5292
- }
5280
+
5281
+ // The scalars come back as 1st class LLVM vals
5282
+ // which we have to stick into global constants.
5283
+ auto g = cx. consts. get( cid) ;
5284
+ llvm. LLVMSetInitializer ( g, v) ;
5285
+ llvm. LLVMSetGlobalConstant ( g, True ) ;
5293
5286
}
5294
5287
5295
5288
fn trans_item( @crate_ctxt cx, & ast. item item) {
@@ -5488,8 +5481,14 @@ fn collect_native_item(&@crate_ctxt cx, @ast.native_item i) -> @crate_ctxt {
5488
5481
fn collect_item( & @crate_ctxt cx, @ast. item i) -> @crate_ctxt {
5489
5482
5490
5483
alt ( i. node) {
5491
- case ( ast. item_const( ?name, _, _, ?cid, _) ) {
5484
+ case ( ast. item_const( ?name, _, _, ?cid, ?ann) ) {
5485
+ auto typ = node_ann_type( cx, ann) ;
5486
+ auto g = llvm. LLVMAddGlobal ( cx. llmod, type_of( cx, typ) ,
5487
+ _str. buf( cx. names. next( name) ) ) ;
5488
+ llvm. LLVMSetLinkage ( g, lib. llvm. LLVMPrivateLinkage
5489
+ as llvm. Linkage ) ;
5492
5490
cx. items. insert( cid, i) ;
5491
+ cx. consts. insert( cid, g) ;
5493
5492
}
5494
5493
5495
5494
case ( ast. item_mod( ?name, ?m, ?mid) ) {
0 commit comments