Repository navigation
verify: Define a signed left shift modulo 2^N from C++20 - #20
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
C++20 defines
E1 << E2for a signedE1as the value congruent toE1 * 2^E2modulo2^N([expr.shift]/2); before C++20 it is undefined for a negativeE1and for a value that does not fit the unsigned type. The verifier applied the C++17 rule under every-std, so with-std=c++20failed a
shiftcheck that C++20 does not have.From C++20 the converter lowers a signed left shift as the unsigned shift, reinterpreted, which is exactly the standard's value; the passivizer then checks only that the amount is below the width. Earlier modes, and right shifts (arithmetic in both, implementation-defined before C++20 and arithmetic in Clang), are unchanged. The language mode is the frontend's to decide, so no other layer changes.
Testing:
suite/shift_language_mode.cppruns every rule under-std=c++17and-std=c++20and fails on main under C++20. Lowering in every mode breaks the C++17 checks, and leaving out the compound assignment breaksm <<= 2. Verify suite: 398 passed, 1 unsupported; it runs as C++17, where the converter builds the same shift as before. Under-std=c++20, a verdict differential against main over the 12 Verify sources with shifts changes only the tests of C++17's undefined signed shifts,unsafe_signed_left_negative,unsafe_signed_left_overflow, andunsafe_i128_left_shift, which now verify;decode_uleb128_length_11, whose shifts are all unsigned, timed out under load in that run.