Skip to content

Commit 04308ce

Browse files
committed
Auto merge of #33488 - eddyb:trans-fixes, r=Aatch
Fix several -Z orbit crater blockers. Fixes 3 of the issues found by @nikomatsakis' crater run with `-Z orbit` forced on: https://gist.github.com/nikomatsakis/6688c30a0e5d3fed07cc1ebd4efb1412 Two of the regressions seemed to be fixed by #33130 and the remaining two are timeouts.
2 parents d658809 + cb3a557 commit 04308ce

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
lines changed

src/librustc_trans/mir/block.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
213213

214214
let extra_args = &args[sig.inputs.len()..];
215215
let extra_args = extra_args.iter().map(|op_arg| {
216-
self.mir.operand_ty(bcx.tcx(), op_arg)
216+
let op_ty = self.mir.operand_ty(bcx.tcx(), op_arg);
217+
bcx.monomorphize(&op_ty)
217218
}).collect::<Vec<_>>();
218219
let fn_ty = callee.direct_fn_type(bcx.ccx(), &extra_args);
219220

src/librustc_trans/mir/lvalue.rs

+16-7
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
}

src/librustc_trans/mir/rvalue.rs

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
5555
}
5656

5757
mir::Rvalue::Cast(mir::CastKind::Unsize, ref source, cast_ty) => {
58+
let cast_ty = bcx.monomorphize(&cast_ty);
59+
5860
if common::type_is_fat_ptr(bcx.tcx(), cast_ty) {
5961
// into-coerce of a thin pointer to a fat pointer - just
6062
// use the operand path.

src/test/run-pass/mir_coercions.rs

+11
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ fn coerce_fat_ptr_wrapper(p: PtrWrapper<Fn(u32) -> u32+Send>)
5555
p
5656
}
5757

58+
#[rustc_mir]
59+
fn coerce_ptr_wrapper_poly<'a, T, Trait: ?Sized>(p: PtrWrapper<'a, T>)
60+
-> PtrWrapper<'a, Trait>
61+
where PtrWrapper<'a, T>: CoerceUnsized<PtrWrapper<'a, Trait>>
62+
{
63+
p
64+
}
5865

5966
fn main() {
6067
let a = [0,1,2];
@@ -73,4 +80,8 @@ fn main() {
7380

7481
let z = coerce_fat_ptr_wrapper(PtrWrapper(2,3,(),&square_local));
7582
assert_eq!((z.3)(6), 36);
83+
84+
let z: PtrWrapper<Fn(u32) -> u32> =
85+
coerce_ptr_wrapper_poly(PtrWrapper(2,3,(),&square_local));
86+
assert_eq!((z.3)(6), 36);
7687
}

src/test/run-pass/mir_trans_calls.rs

+10
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
}

src/test/run-pass/mir_trans_calls_variadic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ extern {
1616
}
1717

1818
#[rustc_mir]
19-
fn test(a: i64, b: i64, c: i64, d: i64, e: i64, f: i64) -> i64 {
19+
fn test<T, U>(a: i64, b: i64, c: i64, d: i64, e: i64, f: T, g: U) -> i64 {
2020
unsafe {
2121
rust_interesting_average(6, a, a as f64,
2222
b, b as f64,
2323
c, c as f64,
2424
d, d as f64,
2525
e, e as f64,
26-
f, f as f64) as i64
26+
f, g) as i64
2727
}
2828
}
2929

3030
fn main(){
31-
assert_eq!(test(10, 20, 30, 40, 50, 60), 70);
31+
assert_eq!(test(10, 20, 30, 40, 50, 60_i64, 60.0_f64), 70);
3232
}

0 commit comments

Comments
 (0)