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

Remove unwrap() from cabi_x86_64.rs #47378

Closed
wants to merge 5 commits into from

Conversation

topecongiro
Copy link
Contributor

@topecongiro topecongiro commented Jan 12, 2018

This PR is a follow-up of #47014. I am not certain whether simply removing unwrap() suffices, but at least no test failed.

Closes #38763. Closes #45662.

@rust-highfive
Copy link
Collaborator

r? @estebank

(rust_highfive has picked a reviewer for you, use r? to override)

@topecongiro
Copy link
Contributor Author

Added a test for #38763.

@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 12, 2018
if let Ok(cls) = cls.as_ref() {
if let Some(target) = cast_target(cls, size) {
arg.cast_to(target);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the tests now passing because of the if let Ok(cls) or the if let Some(target)? I feel like instead of silently passing this should fail with a diagnostic error, but I'm not knowledgeable enough about this part fo the language. Otherwise the code seems ready to merge.

@eddyb could you take a look?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #38763 (comment) - I think this needs further investigation.

let offset = Size::from_bytes(8) * (i as u64);
let target = if size <= offset {
CastTarget::from(lo)
} else {
let hi = reg_component(cls, &mut i, size - offset).unwrap();
let hi = reg_component(cls, &mut i, size - offset)?;
Copy link
Member

@eddyb eddyb Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't seem right - if the unwrap can fail that means there's a logic error somewhere within this file, which this seems to hide.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to call bug!() when this failed.

@topecongiro
Copy link
Contributor Author

@eddyb @estebank Thank you for your reviews!

I updated this PR so that registers are 'allocated' to paddings or i128 args. Do you think this is a better approach?

@eddyb
Copy link
Member

eddyb commented Jan 14, 2018

@topecongiro I'm still not happy - I haven't seen any explanation for what's happening.
I really don't want to paper over whatever bug this may be, which is what using Result does.

@topecongiro
Copy link
Contributor Author

I am sorry for being lazy about explaining what I was working on. Let me clarify a bit.

I first tried to compile the following file using 83ba46f:

// test.rs
#![feature(repr_align)]
#![feature(attr_literals)]

#[repr(align(16))]
pub struct Foo(i32);

#[no_mangle]
pub extern "C" fn foo(x: Foo) {}

fn main() {}

and got the following error (an irrelevant part is omitted):

error: internal compiler error: librustc_trans/cabi_x86_64.rs:236: cast_target() failed: cls [Int, None, None, None, None, None, None, None] size Size { raw: 16 }

Here, the content of cls should be [Int, Int, None, None, None, None, None, None], but it is [Int, None, None, None, None, None, None, None]. c1a08a5 fixes this. e48d452 fixes the similar error when using i128.

I really don't want to paper over whatever bug this may be, which is what using Result does.

The new commits do not paper over errors, they will call bug!() when there is an error. Or do you mean using Result inside classify_arg() is a bad idea?

@eddyb
Copy link
Member

eddyb commented Jan 14, 2018

Or do you mean using Result inside classify_arg() is a bad idea?

Yes, because it should never fail. I think I see what's wrong here, we assumed primitives would fit into u64s - let me try to come up with a very targetted fix for that.

EDIIT: I mean, specifically when u128 is involved. Increased alignment should be ignored.

@eddyb
Copy link
Member

eddyb commented Jan 15, 2018

I've opened #47437 and #47439 which solve the two issues separately.

@topecongiro
Copy link
Contributor Author

Cool, I will close this PR in favor of those two.

@eddyb Thank you very much for your help!

@topecongiro topecongiro deleted the issue-45662 branch January 15, 2018 01:50
@estebank
Copy link
Contributor

estebank commented Jan 15, 2018

@topecongiro thank you for taking the time to dig into this in the first place!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants