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

rust_trans: struct argument over ffi were passed incorrectly in some situations. Change cabi_x86_64 to better model the sysv abi. #27017

Merged
merged 2 commits into from
Oct 15, 2015

Conversation

luqmana
Copy link
Member

@luqmana luqmana commented Jul 13, 2015

Fixes #25594.

@rust-highfive
Copy link
Collaborator

r? @brson

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

@luqmana luqmana force-pushed the 25594-sysv-abi-ffi branch from 9488b75 to 1e1f991 Compare July 13, 2015 17:23
assert(c == 3);
assert(d == 4);
assert(e == 5);
assert(s.a == 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer to use different numeric values here (and in all other tests).

@brson
Copy link
Contributor

brson commented Jul 13, 2015

Nice fixes and good test coverage. Thanks @luqmana

@luqmana luqmana force-pushed the 25594-sysv-abi-ffi branch from 1e1f991 to b399fd0 Compare July 13, 2015 18:45
let ty = x86_64_ty(ccx, *t, |cls| cls.is_pass_byval(), Attribute::ByVal);
arg_tys.push(ty);
}
let mut avail_regs = 6; // RDI, RSI, RDX, RCX, R8, R9
Copy link
Contributor

Choose a reason for hiding this comment

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

The ABI rules require counting both integer and floating-point registers.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes but, this is a kinda simplistic approach similar to what clang does since we need to explicitly tell LLVM whether a struct is passed via some hidden pointer (marked byval) or split up/passed as a FCA. The actual specifics of which register or whether it goes on the stack is handled by LLVM.

Copy link
Contributor

Choose a reason for hiding this comment

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

You still need to track them separately... suppose you have a struct which contains a long long and a double. If you run out of xmm registers, the struct needs to be explicitly byval instead of being split up: otherwise, the integer part of the struct ends up in a register. (clang has similar logic; see https://github.com/llvm-mirror/clang/blob/335cc9e22d8b977d83a12297fc85b6f6be965689/lib/CodeGen/TargetInfo.cpp#L2804 .)

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, forget about that. Updated, thanks!

@luqmana luqmana force-pushed the 25594-sysv-abi-ffi branch 2 times, most recently from b509c2b to 1ed9251 Compare July 13, 2015 21:52
}, Attribute::ByVal);
arg_tys.push(ty);

// An integer or pointer parameter
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment needs to be updated.

@luqmana luqmana force-pushed the 25594-sysv-abi-ffi branch 2 times, most recently from 2d6d4a8 to d4ecbde Compare July 14, 2015 05:04
@huonw
Copy link
Member

huonw commented Jul 15, 2015

r? @rust-lang/compiler

#include <assert.h>

struct Rect {
int a;
Copy link
Member

Choose a reason for hiding this comment

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

Since Rust counterpart uses explicitly sized integers, could this use int32_t rather than int?

@nagisa
Copy link
Member

nagisa commented Jul 15, 2015

I would also like to see a test with a struct which is so big it doesn’t fit into the registers (i.e. 7 integers and/or 9 floats). Other than that, I don’t see anything wrong with this patch.

@luqmana luqmana force-pushed the 25594-sysv-abi-ffi branch 2 times, most recently from e0e8590 to b4dbbc4 Compare July 15, 2015 23:13
@luqmana
Copy link
Member Author

luqmana commented Jul 15, 2015

@nagisa Added a big struct case.

@luqmana luqmana force-pushed the 25594-sysv-abi-ffi branch 2 times, most recently from 0978328 to f0c86cc Compare July 19, 2015 00:58
@bkoropoff
Copy link
Contributor

@bors r+

Nice test coverage. Thanks!

@brson
Copy link
Contributor

brson commented Jul 31, 2015

@bors r+

Not sure why @bors ignored @bkoropoff

@bors
Copy link
Contributor

bors commented Jul 31, 2015

📌 Commit f0c86cc has been approved by brson

@bors
Copy link
Contributor

bors commented Jul 31, 2015

⌛ Testing commit f0c86cc with merge 1e1d32a...

@bors
Copy link
Contributor

bors commented Jul 31, 2015

💔 Test failed - auto-win-gnu-64-opt

@luqmana luqmana force-pushed the 25594-sysv-abi-ffi branch from f0c86cc to 340bdee Compare August 10, 2015 05:22
@luqmana luqmana force-pushed the 25594-sysv-abi-ffi branch from 340bdee to 83dda9d Compare August 23, 2015 20:13
@SimonSapin
Copy link
Contributor

What happened to this? http://buildbot.rust-lang.org/builders/auto-win-gnu-64-opt/builds/912 is now a 404 error.

@luqmana
Copy link
Member Author

luqmana commented Oct 15, 2015

Rebased and #29012 should address the windows failure. Updated the test comments and the test makefile to use not call gcc and friends directly but instead use the utilities that abstract platform differences.

@luqmana
Copy link
Member Author

luqmana commented Oct 15, 2015

@bors: r=bkoropoff

@bors
Copy link
Contributor

bors commented Oct 15, 2015

📌 Commit 670b810 has been approved by bkoropoff

@bors
Copy link
Contributor

bors commented Oct 15, 2015

⌛ Testing commit 670b810 with merge 654ba19...

@bors
Copy link
Contributor

bors commented Oct 15, 2015

💔 Test failed - auto-win-gnu-32-nopt-t

@luqmana luqmana force-pushed the 25594-sysv-abi-ffi branch from 670b810 to 5eb4de1 Compare October 15, 2015 05:08
@luqmana
Copy link
Member Author

luqmana commented Oct 15, 2015

@bors r=bkoropoff

@bors
Copy link
Contributor

bors commented Oct 15, 2015

📌 Commit 5eb4de1 has been approved by bkoropoff

bors added a commit that referenced this pull request Oct 15, 2015
@bors
Copy link
Contributor

bors commented Oct 15, 2015

⌛ Testing commit 5eb4de1 with merge 99dc124...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants