@@ -16,11 +16,11 @@ use abi;
1616use adt;
1717use base;
1818use builder:: Builder ;
19- use common:: { self , BlockAndBuilder , CrateContext , C_uint } ;
19+ use common:: { self , BlockAndBuilder , CrateContext , C_uint , C_undef } ;
2020use consts;
2121use machine;
22+ use type_of:: type_of;
2223use mir:: drop;
23- use llvm;
2424use Disr ;
2525
2626use std:: ptr;
@@ -116,10 +116,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
116116 // Ergo, we return an undef ValueRef, so we do not have to special-case every
117117 // place using lvalues, and could use it the same way you use a regular
118118 // 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 ( ) )
123120 } ;
124121 let fn_return_ty = bcx. monomorphize ( & self . mir . return_ty ) ;
125122 let return_ty = fn_return_ty. unwrap ( ) ;
@@ -228,7 +225,19 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
228225 ret
229226 }
230227 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+ }
232241 }
233242 }
234243 }
0 commit comments