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

overflowing-checking for rhs of shift operators #23536

Merged
merged 5 commits into from
Mar 24, 2015

Conversation

pnkfelix
Copy link
Member

overflow-checking for rhs of shift operators

Subtask of #22020 (RFC 560)

@rust-highfive
Copy link
Collaborator

r? @Aatch

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

@pnkfelix
Copy link
Member Author

cc @nikomatsakis

{
let to_llty = |r| bcx.ccx().tn().type_to_string(Type::from_ref(r));
{
let given_llty = type_of::type_of(bcx.ccx(), rhs_t);
Copy link
Member Author

Choose a reason for hiding this comment

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

ah, this whole sub-block is debugging code that is no longer needed; I will remove it.

@pnkfelix
Copy link
Member Author

One of the tests in this PR uncovered #23551, so don't attempt to merge this until that has a fix (or until I revise the test to sidestep that bug).

This includes a slight refactoring of the `cast_shift_rhs` and related
functions in `trans::base`, so that I can call them from much later in
the compiler's control flow (so that we can clearly dilineate where
automatic conversions of the RHS occur, versus where we check it).

The rhs-checking and fallback-masking is generalized to 8- and 16-bit
values, and the fallback-masking is turned on unconditionally.

Fix rust-lang#10183.

Is this a [breaking-change]?  I would argue it is not; it only adds a
strict definition to what was previously undefined behavior; however,
there might be code that was e.g. assuming that `1_i8 << 17` yields 0.
(This happens in certain contexts and at certain optimization levels.)
Note the tests have been revised to match new semantics for 8- and
16-bit values.
@pnkfelix
Copy link
Member Author

Okay, after discovering that #23551 was a duplicate of #10183 and reading the discussion there further, I have decided to go with @glaebhoerl's advice and ensure that we do not encounter undefined behavior due to the shift's RHS.

This PR has now been updated accordingly, and is ready for review/merge.

@nikomatsakis
Copy link
Contributor

r? @nikomatsakis

@rust-highfive rust-highfive assigned nikomatsakis and unassigned Aatch Mar 20, 2015
@nikomatsakis
Copy link
Contributor

r+ -- This looks good to me. I had two questions though so not informing bors just yet (though no action is needed or requested necessarily).

@pnkfelix
Copy link
Member Author

@nikomatsakis constant evaluation is not yet addressed.

I don't know whether we have a reliable way to force the debug-assertions off, though that sounds like a good thing to have if we do not already have it. I will investigate.

(Still, we probably can land this and leave those as to-do items. In particular, we need to deal with const-evaluation for every operation; not just shifts, and that still remains to be done.)

@pnkfelix
Copy link
Member Author

@bors r=nikomatsakis 61ff823

@bors
Copy link
Contributor

bors commented Mar 21, 2015

⌛ Testing commit 61ff823 with merge c9798cb...

@bors
Copy link
Contributor

bors commented Mar 21, 2015

💔 Test failed - auto-mac-64-opt

@pnkfelix
Copy link
Member Author

odd, thought I had done a full test ... or no, maybe I only did make check and that does not cover these pretty print tests.

@pnkfelix
Copy link
Member Author

(the bug I'm referring to in the commit is #20937 )

@pnkfelix
Copy link
Member Author

@bors r=nikomatsakis 5e47c66

Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 21, 2015
@bors
Copy link
Contributor

bors commented Mar 21, 2015

⌛ Testing commit 5e47c66 with merge 1c9b5a6...

@bors
Copy link
Contributor

bors commented Mar 21, 2015

💔 Test failed - auto-mac-64-nopt-t

@bors
Copy link
Contributor

bors commented Mar 23, 2015

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

@pnkfelix
Copy link
Member Author

failures:
    [run-pass] run-pass/over-constrained-vregs.rs

hmm, I guess I need to pass --disable-optimize-tests to catch cases like this. (Or manually recreate the effect of that flag locally, to save myself some time...)

Update: Oh, it also needs a 32-bit build. Hmm.

@pnkfelix
Copy link
Member Author

@bors r=nikomatsakis bb9d210

1 similar comment
@pnkfelix
Copy link
Member Author

@bors r=nikomatsakis bb9d210

@bors
Copy link
Contributor

bors commented Mar 23, 2015

🙀 bb9d210 is not a valid commit SHA. Please try again with 97c8444.

@pnkfelix
Copy link
Member Author

@bors r=nikomatsakis bb9d210

@bors
Copy link
Contributor

bors commented Mar 23, 2015

🙀 bb9d210c99ab248e81598d70c39c3968ab9d09eb is not a valid commit SHA. Please try again with 97c8444.

@pnkfelix
Copy link
Member Author

@bors r=nikomatsakis bb9d210

@pnkfelix
Copy link
Member Author

@bors p=1

@bors
Copy link
Contributor

bors commented Mar 23, 2015

⌛ Testing commit bb9d210 with merge 9c638f8...

@bors
Copy link
Contributor

bors commented Mar 23, 2015

⛄ The build was interrupted to prioritize another pull request.

@bors
Copy link
Contributor

bors commented Mar 23, 2015

⌛ Testing commit bb9d210 with merge b93456c...

@bors
Copy link
Contributor

bors commented Mar 23, 2015

⛄ The build was interrupted to prioritize another pull request.

@bors
Copy link
Contributor

bors commented Mar 23, 2015

⌛ Testing commit bb9d210 with merge 28a0b25...

bors added a commit that referenced this pull request Mar 23, 2015
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Mar 23, 2015
@bors
Copy link
Contributor

bors commented Mar 24, 2015

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

@pnkfelix
Copy link
Member Author

well, here's hoping the rollup suceeds where this latest merge attempt failed...

@pnkfelix
Copy link
Member Author

@bors retry

@bors
Copy link
Contributor

bors commented Mar 24, 2015

@bors bors merged commit bb9d210 into rust-lang:master Mar 24, 2015
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.

6 participants