-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix oversized loads on x86_64 SysV FFI calls #47614
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
r? @eddyb |
Should casts ever cause oversized loads, or should we not create |
Not sure what you mean by the final size matching the original size, bit
the proper solution would be to have the store happen into an alloca of the
type that you want to pass/return and do the proper bitcast or memcpy
there. And then do a plain load from there.
Am 21.01.2018 13:49 schrieb "Eduard-Mihai Burtescu" <
[email protected]>:
… Should casts ever cause oversized loads, or should we not create
CastTargets larger than the type? Maybe we can redesign the CastTarget
API to make sure the final size matches the original layout?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#47614 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAOGMl7Yxb-diqddZTb5R017316MyYY8ks5tMzJOgaJpZM4RlfSl>
.
|
I mean that either we should always be using |
Uses i24 for x86_64 but i32 for sparc64. In either case it does what I
described above though.
Am 21.01.2018 14:12 schrieb "Eduard-Mihai Burtescu" <
[email protected]>:
… I mean that either we should always be using i24 for 3-byte structs or
handle the i32 correctly. Which one does clang do?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#47614 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAOGMjetk2St-3hXw-HIh9whcD6hbgJnks5tMzfJgaJpZM4RlfSl>
.
|
Ping from triage for you, @eddyb ! |
@bors r+ |
📌 Commit a0aa101 has been approved by |
⌛ Testing commit a0aa101e458735d6282744801416dab4904592e4 with merge e8ece949ff4a8df4ca2ecc922b2c2816c0dbbb44... |
💔 Test failed - status-travis |
--- a/src/test/codegen/repr-transparent.rs
+++ b/src/test/codegen/repr-transparent.rs
@@ -145,7 +145,7 @@ pub struct Rgb8 { r: u8, g: u8, b: u8 }
pub struct Rgb8Wrap(Rgb8);
// NB: closing parenthesis is missing because sometimes the argument has a name and sometimes not
-// CHECK: define i32 @test_Rgb8Wrap(i32
+// CHECK: define i24 @test_Rgb8Wrap(i32
#[no_mangle]
#[cfg(all(target_arch="x86_64", target_os="linux"))]
pub extern fn test_Rgb8Wrap(_: Rgb8Wrap) -> Rgb8Wrap { loop {} }
|
a0aa101
to
8ecadd2
Compare
@bors r=eddyb |
📌 Commit 8ecadd2 has been approved by |
src/test/codegen/repr-transparent.rs
Outdated
@@ -145,7 +145,7 @@ pub struct Rgb8 { r: u8, g: u8, b: u8 } | |||
pub struct Rgb8Wrap(Rgb8); | |||
|
|||
// NB: closing parenthesis is missing because sometimes the argument has a name and sometimes not | |||
// CHECK: define i32 @test_Rgb8Wrap(i32 | |||
// CHECK: define i24 @test_Rgb8Wrap(i32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail on non-x86_64 linux. Probably best to move this test into a separate file with appropriate only-*
/ignore-*
lines.
@bors r- The repr(transparent) test change will fail (see above). |
Haha, I got the logic for the tests backwards, and wondered why the code already seemed prepared for this patch. |
Hi @dotdash, just checking if the PR is still worked on! Could you fix the test as per #47614 (comment)? |
3771c77
to
f08883e
Compare
@rkruppe Like that? |
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// only-x86_64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure but this might need more restrictions, since not all x86_64 targets use the SysV ABI. Or alternatively, make the function below extern "sysv64"
as in the other codegen test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I forgot to add the other only-XXX line that I meant to add, but I think forcing sysv ABI is even better here, so I'll go with that. Thanks for the suggestion
#[repr(transparent)] | ||
pub struct Rgb8Wrap(Rgb8); | ||
|
||
// NB: closing parenthesis is missing because sometimes the argument has a name and sometimes not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside: I think this was an artifact of the previous hack and shouldn't be necessary any more. Not that important, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That shouldn't have made a difference. The only thing that should make a difference here is whether e.g. --emit llvm-ir
is given, making LLVM preserve names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure the difference was due to declaring the function as taking an aggregate vs taking a primitive, and possibly also platform dependent. But whatever, it should definitely be consistent now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you're right, I botched my local test and passed the wrong struct.
src/test/codegen/repr-transparent.rs
Outdated
#[cfg(not(all(target_arch="x86_64", target_os="linux")))] | ||
#[no_mangle] | ||
pub extern fn test_Rgb8Wrap(_: u32) -> u32 { loop {} } | ||
|
||
// Same as with the small struct above: ABI-dependent, we only test the interesting case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment and the one above doesn't quite fit any more. I'd move the union FloatBits
test below into repr-transparent-x86_64.rs
(perhaps better called repr-transparent-sysv64.rs
?) and replace everything from line 126 onwards with:
// All that remains to be tested are aggregates. They are tested in separate files called repr-
// transparent-*.rs with `only-*` or `ignore-*` directives, because the expected LLVM IR
// function signatures vary so much that it's not reasonably possible to cover all of them with a
// single CHECK line.
//
// You may be wondering why we don't just compare the return types and argument types for equality
// with FileCheck regex captures. Well, rustc doesn't perform newtype unwrapping on newtypes
// containing aggregates. This is OK on all ABIs we support, but because LLVM has not gotten rid of
// pointee types yet, the IR function signature will be syntactically different (%Foo* vs
// %FooWrapper*).
f08883e
to
a0e4dd7
Compare
|
||
// CHECK: define i32 @test_SmallUnion(i32) | ||
#[no_mangle] | ||
#[cfg(all(target_arch="x86_64", target_os="linux"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cfg
is not necessary any more, and in fact as written will fail the test on non-linux targets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sigh I shouldn't try to squeeze things in between other tasks.
The x86_64 SysV ABI should use exact sizes for small structs passed in registers, i.e. a struct that occupies 3 bytes should use an i24, instead of the i32 it currently uses. Refs rust-lang#45543
a0e4dd7
to
5f3dc8b
Compare
I hope I didn't miss anything this time around... |
Tests look good now. Let's wait for travis though, since these tests only run on the one target travis actually tests. |
@bors r=eddyb |
📌 Commit 5f3dc8b has been approved by |
Fix oversized loads on x86_64 SysV FFI calls The x86_64 SysV ABI should use exact sizes for small structs passed in registers, i.e. a struct that occupies 3 bytes should use an i24, instead of the i32 it currently uses. Refs #45543
💔 Test failed - status-travis |
Fix oversized loads on x86_64 SysV FFI calls The x86_64 SysV ABI should use exact sizes for small structs passed in registers, i.e. a struct that occupies 3 bytes should use an i24, instead of the i32 it currently uses. Refs #45543
☀️ Test successful - status-appveyor, status-travis |
The x86_64 SysV ABI should use exact sizes for small structs passed in
registers, i.e. a struct that occupies 3 bytes should use an i24,
instead of the i32 it currently uses.
Refs #45543