Skip to content

Fix misoptimizations when matching against strings/slices #22385

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

Merged
merged 1 commit into from
Feb 18, 2015

Conversation

dotdash
Copy link
Contributor

@dotdash dotdash commented Feb 15, 2015

When matching against strings/slices, we call the comparison function
for strings, which takes two string slices by value. The slices are
passed in memory, and currently we just pass in a pointer to the
original slice. That can cause misoptimizations because we emit a call
to llvm.lifetime.end for all by-value arguments at the end of a
function, which in this case marks the original slice as dead.

So we need to properly create copies of the slices to pass them to the
comparison function.

Fixes #22008

@rust-highfive
Copy link
Contributor

r? @nikomatsakis

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

// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

Copy link
Member

Choose a reason for hiding this comment

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

This should probably have a // compile-flags: -O to force optimizations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately this break when the tests are compiled with optimizations, because -O is given twice then. So I'll remove that again.

@dotdash
Copy link
Contributor Author

dotdash commented Feb 15, 2015

Addressed both comments. Thanks!

When matching against strings/slices, we call the comparison function
for strings, which takes two string slices by value. The slices are
passed in memory, and currently we just pass in a pointer to the
original slice. That can cause misoptimizations because we emit a call
to llvm.lifetime.end for all by-value arguments at the end of a
function, which in this case marks the original slice as dead.

So we need to properly create copies of the slices to pass them to the
comparison function.

Fixes rust-lang#22008
@brson
Copy link
Contributor

brson commented Feb 16, 2015

Nice find for a subtle bug.

@nikomatsakis
Copy link
Contributor

@bors r+ 4808561 rollup

@nikomatsakis
Copy link
Contributor

Hmm not sure why I put rollup there. I guess because the patch was so small.

Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 17, 2015
…tsakis

When matching against strings/slices, we call the comparison function
for strings, which takes two string slices by value. The slices are
passed in memory, and currently we just pass in a pointer to the
original slice. That can cause misoptimizations because we emit a call
to llvm.lifetime.end for all by-value arguments at the end of a
function, which in this case marks the original slice as dead.

So we need to properly create copies of the slices to pass them to the
comparison function.

Fixes rust-lang#22008
@huonw huonw merged commit 4808561 into rust-lang:master Feb 18, 2015
@dotdash dotdash deleted the slice_by_val_copy branch March 1, 2015 19:21
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.

Bug in optimiser(maybe)
6 participants