Fix closure arguments which are immediate because of field reordering.
While building immediates goes through type_of::type_of, extracting them must account for field reorderings.
This commit is contained in:
parent
cf5f80c68d
commit
c8c3579bff
@ -11,7 +11,7 @@
|
||||
use llvm::{self, ValueRef};
|
||||
use rustc_const_eval::{ErrKind, ConstEvalErr, note_const_eval_err};
|
||||
use rustc::middle::lang_items;
|
||||
use rustc::ty;
|
||||
use rustc::ty::{self, layout};
|
||||
use rustc::mir;
|
||||
use abi::{Abi, FnType, ArgType};
|
||||
use adt;
|
||||
@ -722,8 +722,14 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
|
||||
}
|
||||
Immediate(llval) => {
|
||||
let l = bcx.ccx().layout_of(tuple.ty);
|
||||
let v = if let layout::Univariant { ref variant, .. } = *l {
|
||||
variant
|
||||
} else {
|
||||
bug!("Not a tuple.");
|
||||
};
|
||||
for (n, &ty) in arg_types.iter().enumerate() {
|
||||
let mut elem = bcx.extract_value(llval, n);
|
||||
let mut elem = bcx.extract_value(llval, v.memory_index[n] as usize);
|
||||
// Truncate bools to i1, if needed
|
||||
if ty.is_bool() && common::val_ty(elem) != Type::i1(bcx.ccx()) {
|
||||
elem = bcx.trunc(elem, Type::i1(bcx.ccx()));
|
||||
|
22
src/test/run-pass/closure-immediate.rs
Normal file
22
src/test/run-pass/closure-immediate.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
// After the work to reoptimize structs, it became possible for immediate logic to fail.
|
||||
// This test verifies that it actually works.
|
||||
|
||||
fn main() {
|
||||
let c = |a: u8, b: u16, c: u8| {
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(b, 2);
|
||||
assert_eq!(c, 3);
|
||||
};
|
||||
c(1, 2, 3);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user