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

trans: always use a memcpy for ABI argument/return casts. #34141

Merged
merged 1 commit into from
Jun 8, 2016

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Jun 7, 2016

When storing incoming arguments or values returned by call/invoke, always do a memcpy from a temporary of the cast type, if there is an ABI cast.
While Clang has gotten smarter (store vs memcpy), a memcpy will always work.
This is what @dotdash has wanted to do all along, and it fixes #32049.

@rust-highfive
Copy link
Collaborator

r? @nrc

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

@eddyb eddyb added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jun 7, 2016
@eddyb
Copy link
Member Author

eddyb commented Jun 7, 2016

Nominated for backporting to beta because it reverts #33872's effect of triggering #32049 in the image crate. #33872 was already accepted, and this PR can be seen as a "more correct" alternative to that.


// We instead thus allocate some scratch space...
let llscratch = AllocaFcx(bcx.fcx(), ty, "abi_cast");
base::Lifetime::End.call(bcx, llscratch);
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be lifetime start?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops...

@nikomatsakis
Copy link
Contributor

@bors r+ p=1

@bors
Copy link
Contributor

bors commented Jun 7, 2016

📌 Commit 2e68f31 has been approved by nikomatsakis

@nikomatsakis
Copy link
Contributor

I'm inclined to beta-accept -- thoughts from @rust-lang/compiler team?

@nagisa
Copy link
Member

nagisa commented Jun 7, 2016

I’m fine with it. My fix wasn’t supposed to be more than a short-term quick-hack anyway (for certain time-pressing reasons like trains rolling over the next day).

EDIT: or rather, please do accept it.

@eddyb
Copy link
Member Author

eddyb commented Jun 7, 2016

@bors r=nikomatsakis p=2

I've rebased this on top of #34128 because it's likely to get in and because I won't be around to babysit it.

@bors
Copy link
Contributor

bors commented Jun 7, 2016

📌 Commit 0d145c9 has been approved by nikomatsakis

@dotdash
Copy link
Contributor

dotdash commented Jun 7, 2016

+1 on the backport

})
impl Lifetime {
pub fn call(self, b: &Builder, ptr: ValueRef) {
core_lifetime_emit(b.ccx, ptr, Lifetime::Start, |ccx, size, lifetime_intrinsic| {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs to be self instead of Lifetime::Start?

Copy link
Member Author

Choose a reason for hiding this comment

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

I... wrote this twice. It was fine the first time :/.

@dotdash
Copy link
Contributor

dotdash commented Jun 7, 2016

Yep, that's much closer (not sure if 100% the same) to what I had in mind. Sorry for not getting that done myself earlier and causing some unnecessary churn :-/

That should also be useful for the outstanding transmute fix of mine that's still missing its MIR part.

Nice!

@eddyb
Copy link
Member Author

eddyb commented Jun 7, 2016

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Jun 7, 2016

📌 Commit d9f93b9 has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Jun 7, 2016

⌛ Testing commit d9f93b9 with merge ab5b316...

@bors
Copy link
Contributor

bors commented Jun 7, 2016

💔 Test failed - auto-win-gnu-32-opt-rustbuild

@arielb1
Copy link
Contributor

arielb1 commented Jun 7, 2016

Real failure:

C:\bot\slave\auto-win-gnu-32-opt-rustbuild\build\src/test\codegen\stores.rs:34:11: error: expected string not found in input
// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[Y8]], i8* [[TMP8]], i64 4, i32 1, i1 false)
          ^
C:\bot\slave\auto-win-gnu-32-opt-rustbuild\build\obj\build\i686-pc-windows-gnu\test\codegen\stores.ll:19:2: note: scanning from here
 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %3, i8* %4, i32 4, i32 1, i1 false)
 ^
C:\bot\slave\auto-win-gnu-32-opt-rustbuild\build\obj\build\i686-pc-windows-gnu\test\codegen\stores.ll:19:2: note: with variable "Y8" equal to "%3"
 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %3, i8* %4, i32 4, i32 1, i1 false)
 ^
C:\bot\slave\auto-win-gnu-32-opt-rustbuild\build\obj\build\i686-pc-windows-gnu\test\codegen\stores.ll:19:2: note: with variable "TMP8" equal to "%4"
 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %3, i8* %4, i32 4, i32 1, i1 false)
 ^
C:\bot\slave\auto-win-gnu-32-opt-rustbuild\build\src/test\codegen\stores.rs:49:11: error: expected string not found in input
// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[Y8]], i8* [[TMP8]], i64 4, i32 1, i1 false)
          ^
C:\bot\slave\auto-win-gnu-32-opt-rustbuild\build\obj\build\i686-pc-windows-gnu\test\codegen\stores.ll:50:2: note: scanning from here
 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %3, i8* %4, i32 4, i32 1, i1 false)
 ^
C:\bot\slave\auto-win-gnu-32-opt-rustbuild\build\obj\build\i686-pc-windows-gnu\test\codegen\stores.ll:50:2: note: with variable "Y8" equal to "%3"
 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %3, i8* %4, i32 4, i32 1, i1 false)
 ^
C:\bot\slave\auto-win-gnu-32-opt-rustbuild\build\obj\build\i686-pc-windows-gnu\test\codegen\stores.ll:50:2: note: with variable "TMP8" equal to "%4"
 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %3, i8* %4, i32 4, i32 1, i1 false)

Difference: @llvm.memcpy.p0i8.p0i8.i64 vs. @llvm.memcpy.p0i8.p0i8.i32

@eddyb
Copy link
Member Author

eddyb commented Jun 7, 2016

@arielb1 Who needs 32-bit anyway /s.

@eddyb
Copy link
Member Author

eddyb commented Jun 7, 2016

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Jun 7, 2016

📌 Commit e252865 has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Jun 7, 2016

⌛ Testing commit e252865 with merge ec872dc...

bors added a commit that referenced this pull request Jun 7, 2016
trans: always use a memcpy for ABI argument/return casts.

When storing incoming arguments or values returned by call/invoke, always do a `memcpy` from a temporary of the cast type, if there is an ABI cast.
While Clang has gotten smarter ([store](https://godbolt.org/g/EphFuK) vs [memcpy](https://godbolt.org/g/5dikH9)), a `memcpy` will always work.
This is what @dotdash has wanted to do all along, and it fixes #32049.
@bors bors merged commit e252865 into rust-lang:master Jun 8, 2016
@eddyb eddyb deleted the trans-abi-memcpy branch June 8, 2016 00:36
@arielb1 arielb1 added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 9, 2016
@nikomatsakis nikomatsakis added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Jun 9, 2016
@brson brson removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jun 28, 2016
brson added a commit that referenced this pull request Jun 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LLVM error while cross-compiling Servo for ARM
9 participants