@@ -161,13 +161,17 @@ pub fn addr_of(ccx: &CrateContext,
161
161
gv
162
162
}
163
163
164
- fn const_deref_ptr ( cx : & CrateContext , v : ValueRef ) -> ValueRef {
164
+ /// Deref a constant pointer
165
+ fn load_const ( cx : & CrateContext , v : ValueRef , t : Ty ) -> ValueRef {
165
166
let v = match cx. const_unsized ( ) . borrow ( ) . get ( & v) {
166
167
Some ( & v) => v,
167
168
None => v
168
169
} ;
169
- unsafe {
170
- llvm:: LLVMGetInitializer ( v)
170
+ let d = unsafe { llvm:: LLVMGetInitializer ( v) } ;
171
+ if t. is_bool ( ) {
172
+ unsafe { llvm:: LLVMConstTrunc ( d, Type :: i1 ( cx) . to_ref ( ) ) }
173
+ } else {
174
+ d
171
175
}
172
176
}
173
177
@@ -178,7 +182,7 @@ fn const_deref<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
178
182
match ty. builtin_deref ( true , ty:: NoPreference ) {
179
183
Some ( mt) => {
180
184
if type_is_sized ( cx. tcx ( ) , mt. ty ) {
181
- ( const_deref_ptr ( cx, v) , mt. ty )
185
+ ( load_const ( cx, v, mt . ty ) , mt. ty )
182
186
} else {
183
187
// Derefing a fat pointer does not change the representation,
184
188
// just the type to the unsized contents.
@@ -588,7 +592,10 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
588
592
let is_float = ty. is_fp ( ) ;
589
593
let signed = ty. is_signed ( ) ;
590
594
591
- let ( te2, _) = try!( const_expr ( cx, & e2, param_substs, fn_args, trueconst) ) ;
595
+ let ( te2, ty2) = try!( const_expr ( cx, & e2, param_substs, fn_args, trueconst) ) ;
596
+ debug ! ( "const_expr_unadjusted: te2={}, ty={:?}" ,
597
+ cx. tn( ) . val_to_string( te2) ,
598
+ ty2) ;
592
599
593
600
try!( check_binary_expr_validity ( cx, e, ty, te1, te2, trueconst) ) ;
594
601
@@ -671,13 +678,13 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
671
678
} ;
672
679
let ( arr, len) = match bt. sty {
673
680
ty:: TyArray ( _, u) => ( bv, C_uint ( cx, u) ) ,
674
- ty:: TySlice ( _ ) | ty:: TyStr => {
681
+ ty:: TySlice ( .. ) | ty:: TyStr => {
675
682
let e1 = const_get_elt ( cx, bv, & [ 0 ] ) ;
676
- ( const_deref_ptr ( cx, e1) , const_get_elt ( cx, bv, & [ 1 ] ) )
683
+ ( load_const ( cx, e1, bt ) , const_get_elt ( cx, bv, & [ 1 ] ) )
677
684
} ,
678
685
ty:: TyRef ( _, mt) => match mt. ty . sty {
679
686
ty:: TyArray ( _, u) => {
680
- ( const_deref_ptr ( cx, bv) , C_uint ( cx, u) )
687
+ ( load_const ( cx, bv, mt . ty ) , C_uint ( cx, u) )
681
688
} ,
682
689
_ => cx. sess ( ) . span_bug ( base. span ,
683
690
& format ! ( "index-expr base must be a vector \
@@ -891,7 +898,8 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
891
898
expr:: trans_def_fn_unadjusted ( cx, e, def, param_substs) . val
892
899
}
893
900
Def :: Const ( def_id) | Def :: AssociatedConst ( def_id) => {
894
- const_deref_ptr ( cx, try!( get_const_val ( cx, def_id, e, param_substs) ) )
901
+ load_const ( cx, try!( get_const_val ( cx, def_id, e, param_substs) ) ,
902
+ ety)
895
903
}
896
904
Def :: Variant ( enum_did, variant_did) => {
897
905
let vinfo = cx. tcx ( ) . lookup_adt_def ( enum_did) . variant_with_id ( variant_did) ;
0 commit comments