Skip to content

Commit 34505e2

Browse files
committed
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.
2 parents 0d531bf + 22fa769 commit 34505e2

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/librustc_trans/mir/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc::mir::repr as mir;
1616
use rustc::mir::tcx::LvalueTy;
1717
use session::config::FullDebugInfo;
1818
use base;
19-
use common::{self, Block, BlockAndBuilder, CrateContext, FunctionContext};
19+
use common::{self, Block, BlockAndBuilder, CrateContext, FunctionContext, C_null};
2020
use debuginfo::{self, declare_local, DebugLoc, VariableAccess, VariableKind};
2121
use machine;
2222
use type_of;
@@ -130,11 +130,12 @@ impl<'tcx> TempRef<'tcx> {
130130
// Zero-size temporaries aren't always initialized, which
131131
// doesn't matter because they don't contain data, but
132132
// we need something in the operand.
133-
let nil = common::C_nil(ccx);
133+
let llty = type_of::type_of(ccx, ty);
134134
let val = if common::type_is_imm_pair(ccx, ty) {
135-
OperandValue::Pair(nil, nil)
135+
let fields = llty.field_types();
136+
OperandValue::Pair(C_null(fields[0]), C_null(fields[1]))
136137
} else {
137-
OperandValue::Immediate(nil)
138+
OperandValue::Immediate(C_null(llty))
138139
};
139140
let op = OperandRef {
140141
val: val,

src/test/run-pass/mir_trans_calls.rs

+15
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fn test2(a: isize) -> isize {
3030
callee(a)
3131
}
3232

33+
#[derive(PartialEq, Eq, Debug)]
3334
struct Foo;
3435
impl Foo {
3536
fn inherent_method(&self, a: isize) -> isize { a }
@@ -157,6 +158,19 @@ fn test_fn_ignored_pair_0() {
157158
test_fn_ignored_pair().0
158159
}
159160

161+
#[rustc_mir]
162+
fn id<T>(x: T) -> T { x }
163+
164+
#[rustc_mir]
165+
fn ignored_pair_named() -> (Foo, Foo) {
166+
(Foo, Foo)
167+
}
168+
169+
#[rustc_mir]
170+
fn test_fn_ignored_pair_named() -> (Foo, Foo) {
171+
id(ignored_pair_named())
172+
}
173+
160174
fn main() {
161175
assert_eq!(test1(1, (2, 3), &[4, 5, 6]), (1, (2, 3), &[4, 5, 6][..]));
162176
assert_eq!(test2(98), 98);
@@ -181,4 +195,5 @@ fn main() {
181195
assert_eq!(test_fn_transmute_zst(()), [()]);
182196

183197
assert_eq!(test_fn_ignored_pair_0(), ());
198+
assert_eq!(test_fn_ignored_pair_named(), (Foo, Foo));
184199
}

0 commit comments

Comments
 (0)