@@ -20,6 +20,7 @@ use middle::trans::expr;
20
20
use middle:: trans:: machine;
21
21
use middle:: trans:: type_of;
22
22
use middle:: ty;
23
+ use util:: ppaux:: { expr_repr, ty_to_str} ;
23
24
24
25
use core:: libc:: c_uint;
25
26
use syntax:: { ast, ast_util, codemap, ast_map} ;
@@ -150,6 +151,24 @@ pub fn get_const_val(cx: @CrateContext, def_id: ast::def_id) -> ValueRef {
150
151
}
151
152
152
153
pub fn const_expr ( cx : @CrateContext , e : @ast:: expr ) -> ValueRef {
154
+ let ety = ty:: expr_ty_adjusted ( cx. tcx , e) ;
155
+ let llty = type_of:: sizing_type_of ( cx, ety) ;
156
+ let llconst = const_expr_unchecked ( cx, e) ;
157
+ let csize = machine:: llsize_of_alloc ( cx, val_ty ( llconst) ) ;
158
+ let tsize = machine:: llsize_of_alloc ( cx, llty) ;
159
+ if csize != tsize {
160
+ unsafe {
161
+ llvm:: LLVMDumpValue ( llconst) ;
162
+ llvm:: LLVMDumpValue ( C_null ( llty) ) ;
163
+ }
164
+ cx. sess . bug ( fmt ! ( "const %s of type %s has size %u instead of %u" ,
165
+ expr_repr( cx. tcx, e) , ty_to_str( cx. tcx, ety) ,
166
+ csize, tsize) ) ;
167
+ }
168
+ llconst
169
+ }
170
+
171
+ fn const_expr_unchecked( cx : @CrateContext , e : @ast:: expr ) -> ValueRef {
153
172
unsafe {
154
173
let _icx = cx. insn_ctxt ( "const_expr" ) ;
155
174
return match /*bad*/ copy e. node {
0 commit comments