Auto merge of #34167 - eddyb:fix-pairs-for-real, r=nikomatsakis

trans: don't misuse C_nil for ZSTs other than ().

`C_nil` is actually `C_null` for `()` so `TempRef::new_operand` was treating all ZSTs as `()`.
This should allow running Servo with `RUSTFLAGS=-Zorbit`, assuming there are no other bugs.
This commit is contained in:
bors 2016-06-08 16:41:01 -07:00
commit 34505e2228
2 changed files with 20 additions and 4 deletions

View File

@ -16,7 +16,7 @@
use rustc::mir::tcx::LvalueTy;
use session::config::FullDebugInfo;
use base;
use common::{self, Block, BlockAndBuilder, CrateContext, FunctionContext};
use common::{self, Block, BlockAndBuilder, CrateContext, FunctionContext, C_null};
use debuginfo::{self, declare_local, DebugLoc, VariableAccess, VariableKind};
use machine;
use type_of;
@ -130,11 +130,12 @@ fn new_operand<'bcx>(ccx: &CrateContext<'bcx, 'tcx>,
// Zero-size temporaries aren't always initialized, which
// doesn't matter because they don't contain data, but
// we need something in the operand.
let nil = common::C_nil(ccx);
let llty = type_of::type_of(ccx, ty);
let val = if common::type_is_imm_pair(ccx, ty) {
OperandValue::Pair(nil, nil)
let fields = llty.field_types();
OperandValue::Pair(C_null(fields[0]), C_null(fields[1]))
} else {
OperandValue::Immediate(nil)
OperandValue::Immediate(C_null(llty))
};
let op = OperandRef {
val: val,

View File

@ -30,6 +30,7 @@ fn callee(a: isize) -> isize {
callee(a)
}
#[derive(PartialEq, Eq, Debug)]
struct Foo;
impl Foo {
fn inherent_method(&self, a: isize) -> isize { a }
@ -157,6 +158,19 @@ fn test_fn_ignored_pair_0() {
test_fn_ignored_pair().0
}
#[rustc_mir]
fn id<T>(x: T) -> T { x }
#[rustc_mir]
fn ignored_pair_named() -> (Foo, Foo) {
(Foo, Foo)
}
#[rustc_mir]
fn test_fn_ignored_pair_named() -> (Foo, Foo) {
id(ignored_pair_named())
}
fn main() {
assert_eq!(test1(1, (2, 3), &[4, 5, 6]), (1, (2, 3), &[4, 5, 6][..]));
assert_eq!(test2(98), 98);
@ -181,4 +195,5 @@ fn main() {
assert_eq!(test_fn_transmute_zst(()), [()]);
assert_eq!(test_fn_ignored_pair_0(), ());
assert_eq!(test_fn_ignored_pair_named(), (Foo, Foo));
}