Skip to content

Commit f16bfab

Browse files
committed
---
yaml --- r: 278238 b: refs/heads/auto c: cb3a557 h: refs/heads/master
1 parent 655401c commit f16bfab

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: d460597e3373c7ec2a54f64faf6a1f8874b958bd
11+
refs/heads/auto: cb3a557e0cae65d5d4a1d87ee4316e7995188c34
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/src/librustc_trans/mir/lvalue.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ use abi;
1616
use adt;
1717
use base;
1818
use builder::Builder;
19-
use common::{self, BlockAndBuilder, CrateContext, C_uint};
19+
use common::{self, BlockAndBuilder, CrateContext, C_uint, C_undef};
2020
use consts;
2121
use machine;
22+
use type_of::type_of;
2223
use mir::drop;
23-
use llvm;
2424
use Disr;
2525

2626
use 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
}

branches/auto/src/test/run-pass/mir_trans_calls.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@ fn test_fn_nil_call<F>(f: &F) -> i32
138138
f()
139139
}
140140

141+
#[rustc_mir]
142+
fn test_fn_transmute_zst(x: ()) -> [(); 1] {
143+
fn id<T>(x: T) -> T {x}
144+
145+
id(unsafe {
146+
std::mem::transmute(x)
147+
})
148+
}
149+
141150
fn main() {
142151
assert_eq!(test1(1, (2, 3), &[4, 5, 6]), (1, (2, 3), &[4, 5, 6][..]));
143152
assert_eq!(test2(98), 98);
@@ -159,4 +168,5 @@ fn main() {
159168
assert_eq!(test_fn_direct_call(&closure, 100, 4), 324);
160169

161170
assert_eq!(test_fn_nil_call(&(|| 42)), 42);
171+
assert_eq!(test_fn_transmute_zst(()), [()]);
162172
}

0 commit comments

Comments
 (0)