Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc_trans: remove an unwrap by replacing a bool with Result. #47626

Merged
merged 1 commit into from
Jan 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions src/librustc_trans/cabi_x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,44 +194,48 @@ pub fn compute_abi_info<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, fty: &mut FnType<'tc
let mut sse_regs = 8; // XMM0-7

let mut x86_64_ty = |arg: &mut ArgType<'tcx>, is_arg: bool| {
let cls = classify_arg(cx, arg);
let mut cls_or_mem = classify_arg(cx, arg);

let mut needed_int = 0;
let mut needed_sse = 0;
let in_mem = match cls {
Err(Memory) => true,
Ok(ref cls) if is_arg => {
for &c in cls {
if is_arg {
if let Ok(cls) = cls_or_mem {
for &c in &cls {
match c {
Class::Int => needed_int += 1,
Class::Sse => needed_sse += 1,
_ => {}
}
}
arg.layout.is_aggregate() &&
(int_regs < needed_int || sse_regs < needed_sse)
if arg.layout.is_aggregate() {
if int_regs < needed_int || sse_regs < needed_sse {
cls_or_mem = Err(Memory);
}
}
}
Ok(_) => false
};
}

if in_mem {
if is_arg {
arg.make_indirect_byval();
} else {
// `sret` parameter thus one less integer register available
arg.make_indirect();
int_regs -= 1;
match cls_or_mem {
Err(Memory) => {
if is_arg {
arg.make_indirect_byval();
} else {
// `sret` parameter thus one less integer register available
arg.make_indirect();
int_regs -= 1;
}
}
} else {
// split into sized chunks passed individually
int_regs -= needed_int;
sse_regs -= needed_sse;

if arg.layout.is_aggregate() {
let size = arg.layout.size;
arg.cast_to(cast_target(cls.as_ref().unwrap(), size))
} else {
arg.extend_integer_width_to(32);
Ok(ref cls) => {
// split into sized chunks passed individually
int_regs -= needed_int;
sse_regs -= needed_sse;

if arg.layout.is_aggregate() {
let size = arg.layout.size;
arg.cast_to(cast_target(cls, size))
} else {
arg.extend_integer_width_to(32);
}
}
}
};
Expand Down