@@ -83,23 +83,18 @@ pub fn const_ptrcast(cx: &mut CrateContext, a: ValueRef, t: Type) -> ValueRef {
83
83
}
84
84
}
85
85
86
- pub fn const_vec ( cx : @mut CrateContext , e : & ast:: Expr , es : & [ @ast:: Expr ] )
87
- -> ( ValueRef , ValueRef , Type , bool ) {
88
- unsafe {
89
- let vec_ty = ty:: expr_ty ( cx. tcx , e) ;
90
- let unit_ty = ty:: sequence_element_type ( cx. tcx , vec_ty) ;
91
- let llunitty = type_of:: type_of ( cx, unit_ty) ;
92
- let unit_sz = machine:: llsize_of ( cx, llunitty) ;
93
- let sz = llvm:: LLVMConstMul ( C_uint ( cx, es. len ( ) ) , unit_sz) ;
94
- let ( vs, inlineable) = vec:: unzip ( es. iter ( ) . map ( |e| const_expr ( cx, * e) ) ) ;
95
- // If the vector contains enums, an LLVM array won't work.
96
- let v = if vs. iter ( ) . any ( |vi| val_ty ( * vi) != llunitty) {
97
- C_struct ( vs, false )
98
- } else {
99
- C_array ( llunitty, vs)
100
- } ;
101
- return ( v, sz, llunitty, inlineable. iter ( ) . fold ( true , |a, & b| a && b) ) ;
102
- }
86
+ fn const_vec ( cx : @mut CrateContext , e : & ast:: Expr , es : & [ @ast:: Expr ] ) -> ( ValueRef , Type , bool ) {
87
+ let vec_ty = ty:: expr_ty ( cx. tcx , e) ;
88
+ let unit_ty = ty:: sequence_element_type ( cx. tcx , vec_ty) ;
89
+ let llunitty = type_of:: type_of ( cx, unit_ty) ;
90
+ let ( vs, inlineable) = vec:: unzip ( es. iter ( ) . map ( |e| const_expr ( cx, * e) ) ) ;
91
+ // If the vector contains enums, an LLVM array won't work.
92
+ let v = if vs. iter ( ) . any ( |vi| val_ty ( * vi) != llunitty) {
93
+ C_struct ( vs, false )
94
+ } else {
95
+ C_array ( llunitty, vs)
96
+ } ;
97
+ ( v, llunitty, inlineable. iter ( ) . fold ( true , |a, & b| a && b) )
103
98
}
104
99
105
100
fn const_addr_of ( cx : & mut CrateContext , cv : ValueRef ) -> ValueRef {
@@ -225,9 +220,8 @@ pub fn const_expr(cx: @mut CrateContext, e: &ast::Expr) -> (ValueRef, bool) {
225
220
assert_eq ! ( abi:: slice_elt_len, 1 ) ;
226
221
227
222
match ty:: get ( ty) . sty {
228
- ty:: ty_evec( _, ty:: vstore_fixed( * ) ) => {
229
- let size = machine:: llsize_of ( cx, val_ty ( llconst) ) ;
230
- llconst = C_struct ( [ llptr, size] , false ) ;
223
+ ty:: ty_evec( _, ty:: vstore_fixed( len) ) => {
224
+ llconst = C_struct ( [ llptr, C_uint ( cx, len) ] , false ) ;
231
225
}
232
226
_ => { }
233
227
}
@@ -412,14 +406,8 @@ fn const_expr_unadjusted(cx: @mut CrateContext,
412
406
( bv, C_uint ( cx, u) ) ,
413
407
414
408
ty:: vstore_slice( _) => {
415
- let unit_ty = ty:: sequence_element_type ( cx. tcx , bt) ;
416
- let llunitty = type_of:: type_of ( cx, unit_ty) ;
417
- let unit_sz = machine:: llsize_of ( cx, llunitty) ;
418
-
419
409
let e1 = const_get_elt ( cx, bv, [ 0 ] ) ;
420
- ( const_deref_ptr ( cx, e1) ,
421
- llvm:: LLVMConstUDiv ( const_get_elt ( cx, bv, [ 1 ] ) ,
422
- unit_sz) )
410
+ ( const_deref_ptr ( cx, e1) , const_get_elt ( cx, bv, [ 1 ] ) )
423
411
} ,
424
412
_ => cx. sess . span_bug ( base. span ,
425
413
"index-expr base must be fixed-size or slice" )
@@ -538,7 +526,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext,
538
526
}
539
527
}
540
528
ast:: ExprVec ( ref es, ast:: MutImmutable ) => {
541
- let ( v, _, _ , inlineable) = const_vec ( cx, e, * es) ;
529
+ let ( v, _, inlineable) = const_vec ( cx, e, * es) ;
542
530
( v, inlineable)
543
531
}
544
532
ast:: ExprVstore ( sub, ast:: ExprVstoreSlice ) => {
@@ -550,7 +538,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext,
550
538
}
551
539
}
552
540
ast:: ExprVec ( ref es, ast:: MutImmutable ) => {
553
- let ( cv, sz , llunitty, _) = const_vec ( cx, e, * es) ;
541
+ let ( cv, llunitty, _) = const_vec ( cx, e, * es) ;
554
542
let llty = val_ty ( cv) ;
555
543
let gv = do "const" . with_c_str |name| {
556
544
llvm:: LLVMAddGlobal ( cx. llmod , llty. to_ref ( ) , name)
@@ -559,7 +547,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext,
559
547
llvm:: LLVMSetGlobalConstant ( gv, True ) ;
560
548
SetLinkage ( gv, PrivateLinkage ) ;
561
549
let p = const_ptrcast ( cx, gv, llunitty) ;
562
- ( C_struct ( [ p, sz ] , false ) , false )
550
+ ( C_struct ( [ p, C_uint ( cx , es . len ( ) ) ] , false ) , false )
563
551
}
564
552
_ => cx. sess . span_bug ( e. span , "bad const-slice expr" )
565
553
}
0 commit comments