@@ -16,11 +16,11 @@ use abi;
16
16
use adt;
17
17
use base;
18
18
use builder:: Builder ;
19
- use common:: { self , BlockAndBuilder , CrateContext , C_uint } ;
19
+ use common:: { self , BlockAndBuilder , CrateContext , C_uint , C_undef } ;
20
20
use consts;
21
21
use machine;
22
+ use type_of:: type_of;
22
23
use mir:: drop;
23
- use llvm;
24
24
use Disr ;
25
25
26
26
use std:: ptr;
@@ -116,10 +116,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
116
116
// Ergo, we return an undef ValueRef, so we do not have to special-case every
117
117
// place using lvalues, and could use it the same way you use a regular
118
118
// ReturnPointer LValue (i.e. store into it, load from it etc).
119
- let llty = fcx. fn_ty . ret . original_ty . ptr_to ( ) ;
120
- unsafe {
121
- llvm:: LLVMGetUndef ( llty. to_ref ( ) )
122
- }
119
+ C_undef ( fcx. fn_ty . ret . original_ty . ptr_to ( ) )
123
120
} ;
124
121
let fn_return_ty = bcx. monomorphize ( & self . mir . return_ty ) ;
125
122
let return_ty = fn_return_ty. unwrap ( ) ;
@@ -228,7 +225,19 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
228
225
ret
229
226
}
230
227
TempRef :: Operand ( Some ( _) ) => {
231
- bug ! ( "Lvalue temp already set" ) ;
228
+ let lvalue_ty = self . mir . lvalue_ty ( bcx. tcx ( ) , lvalue) ;
229
+ let lvalue_ty = bcx. monomorphize ( & lvalue_ty) ;
230
+
231
+ // See comments in TempRef::new_operand as to why
232
+ // we always have Some in a ZST TempRef::Operand.
233
+ let ty = lvalue_ty. to_ty ( bcx. tcx ( ) ) ;
234
+ if common:: type_is_zero_size ( bcx. ccx ( ) , ty) {
235
+ // Pass an undef pointer as no stores can actually occur.
236
+ let llptr = C_undef ( type_of ( bcx. ccx ( ) , ty) . ptr_to ( ) ) ;
237
+ f ( self , LvalueRef :: new_sized ( llptr, lvalue_ty) )
238
+ } else {
239
+ bug ! ( "Lvalue temp already set" ) ;
240
+ }
232
241
}
233
242
}
234
243
}
0 commit comments