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

Fix integer overflow in rotate_left #61454

Merged
merged 1 commit into from Jun 4, 2019

Conversation

Projects
None yet
6 participants
@lzutao
Copy link
Contributor

commented Jun 2, 2019

Closes #61406
r? @RalfJung

@lzutao

This comment was marked as resolved.

Copy link
Contributor Author

commented Jun 2, 2019

@rustbot modify labels: T-compiler

@rustbot rustbot added the T-compiler label Jun 2, 2019

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

commented Jun 2, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:0a4c0178:start=1559472178505729458,finish=1559472179317808115,duration=812078657
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
[00:58:53] .................................................................................................... 400/5609
[00:58:57] ...................................................................................................i 500/5609
[00:59:00] .................................................................................................... 600/5609
[00:59:05] .................................................................................................... 700/5609
[00:59:10] .................................................................................................F.. 800/5609
[00:59:18] i................................................................................................... 1000/5609
[00:59:22] .................iiiii.............................................................................. 1100/5609
[00:59:25] .................................................................................................... 1200/5609
[00:59:27] .................................................................................................... 1300/5609
---
[01:02:23] 
[01:02:23] 
[01:02:23] The actual stderr differed from the expected stderr.
[01:02:23] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-int-rotate/const-int-rotate.stderr
[01:02:23] To update references, rerun the tests and pass the `--bless` flag
[01:02:23] To only update this specific test, also pass `--test-args consts/const-int-rotate.rs`
[01:02:23] error: 1 errors occurred comparing output.
[01:02:23] status: exit code: 1
[01:02:23] status: exit code: 1
[01:02:23] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/consts/const-int-rotate.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-int-rotate" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-int-rotate/auxiliary" "-A" "unused"
[01:02:23] ------------------------------------------
[01:02:23] 
[01:02:23] ------------------------------------------
[01:02:23] stderr:
[01:02:23] stderr:
[01:02:23] ------------------------------------------
[01:02:23] error[E0716]: temporary value dropped while borrowed
[01:02:23]   --> /checkout/src/test/ui/consts/const-int-rotate.rs:2:28
[01:02:23]    |
[01:02:23] LL |     let x: &'static i32 = &(5_i32.rotate_left(3));
[01:02:23]    |            ------------    ^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
[01:02:23]    |            type annotation requires that borrow lasts for `'static`
[01:02:23] ...
[01:02:23] LL | }
[01:02:23]    | - temporary value is freed at the end of this statement
[01:02:23]    | - temporary value is freed at the end of this statement
[01:02:23] 
[01:02:23] error[E0716]: temporary value dropped while borrowed
[01:02:23]   --> /checkout/src/test/ui/consts/const-int-rotate.rs:4:28
[01:02:23]    |
[01:02:23] LL |     let y: &'static i32 = &(5_i32.rotate_right(3));
[01:02:23]    |            ------------    ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
[01:02:23]    |            type annotation requires that borrow lasts for `'static`
[01:02:23] ...
[01:02:23] LL | }
[01:02:23]    | - temporary value is freed at the end of this statement
---
[01:02:23] thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:521:22
[01:02:23] note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
[01:02:23] 
[01:02:23] 
[01:02:23] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:02:23] 
[01:02:23] 
[01:02:23] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:02:23] Build completed unsuccessfully in 0:57:24
---
travis_time:end:3774cd20:start=1559475935054214255,finish=1559475935060100708,duration=5886453
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0faff5f0
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; t

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@lzutao lzutao force-pushed the lzutao:ice-rotate_left branch from f675836 to e7964db Jun 2, 2019

@@ -3,4 +3,5 @@ fn main() {
//~^ ERROR temporary value dropped while borrowed
let y: &'static i32 = &(5_i32.rotate_right(3));
//~^ ERROR temporary value dropped while borrowed
assert_eq!(0i16.rotate_left(124), 0);

This comment has been minimized.

Copy link
@RalfJung

RalfJung Jun 2, 2019

Member

Uh, this is weird. @oli-obk what kind of test is this? I thought it would test functionality for rotate in CTFE but that does not seem to be the case. Do we have any test that does that?

@lzutao in any case, we want to test functionality here, so please move the actual call to within a const item. Something like

const X: i16 = 0i16.rotate_left(124);

This comment has been minimized.

Copy link
@oli-obk

oli-obk Jun 2, 2019

Contributor

The above code just checks that we don't promote calls to the rotate_* methods. The actual tests are in https://github.com/rust-lang/rust/blob/9ebf47851a357faa4cd97f4b1dc7835f6376e639/src/test/run-pass/const-int-rotate.rs

This comment has been minimized.

Copy link
@RalfJung

RalfJung Jun 2, 2019

Member

Ah, thanks!

Both this test here and that one suffer for a severe lack of comments (e.g. for stuff like the ident function).

@lzutao lzutao force-pushed the lzutao:ice-rotate_left branch from e7964db to 0532611 Jun 2, 2019

@RalfJung

This comment has been minimized.

Copy link
Member

commented Jun 2, 2019

@lzutao so please move the new test to src/test/run-pass/const-int-rotate.rs. Please also add a test for rotate_right. See this for some inspiration for test cases.

(Oh, and a force-push does not trigger any notifications, so please write a message here when you think this is ready for another round of review. :)

@lzutao lzutao force-pushed the lzutao:ice-rotate_left branch 3 times, most recently from 531e8f2 to 0b2e00c Jun 4, 2019

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Jun 4, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:1b822838:start=1559644782713663012,finish=1559644783537671140,duration=824008128
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
[01:01:27] .................................................................................................... 100/2923
[01:01:39] .............................................................................i...................... 200/2923
[01:01:48] .................................................................................................... 300/2923
[01:01:59] .................................................................................................... 400/2923
[01:02:08] ....................................F............................................................... 500/2923
[01:02:35] .................................................................................................... 700/2923
[01:02:47] .................................................................................................... 800/2923
[01:02:56] .................................................................................................... 900/2923
[01:03:10] .................................................................................................... 1000/2923
---
[01:07:45] thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:521:22
[01:07:45] note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
[01:07:45] 
[01:07:45] 
[01:07:45] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/run-pass" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "run-pass" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:07:45] 
[01:07:45] 
[01:07:45] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:07:45] Build completed unsuccessfully in 1:02:58
---
travis_time:end:1337b82d:start=1559648862274553568,finish=1559648862279712973,duration=5159405
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:01030324
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:12e66b3e
travis_time:start:12e66b3e
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:11f96ec8
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@lzutao lzutao force-pushed the lzutao:ice-rotate_left branch from 0b2e00c to c2e7b21 Jun 4, 2019

@lzutao

This comment has been minimized.

Copy link
Contributor Author

commented Jun 4, 2019

@RalfJung I think this PR is ready for review again.

@RalfJung

This comment has been minimized.

Copy link
Member

commented Jun 4, 2019

This looks great, thanks a lot!

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

commented Jun 4, 2019

📌 Commit c2e7b21 has been approved by RalfJung

@RalfJung

This comment has been minimized.

Copy link
Member

commented Jun 4, 2019

Actually could you squash the commits and remove the "WIP" from the commit message?

@bors r-

@lzutao lzutao force-pushed the lzutao:ice-rotate_left branch from c2e7b21 to d392cb5 Jun 4, 2019

@lzutao

This comment has been minimized.

Copy link
Contributor Author

commented Jun 4, 2019

Ping again, I squashed those two commits.

@RalfJung

This comment has been minimized.

Copy link
Member

commented Jun 4, 2019

Awesome!

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

commented Jun 4, 2019

📌 Commit d392cb5 has been approved by RalfJung

@lzutao

This comment has been minimized.

Copy link
Contributor Author

commented Jun 4, 2019

@bors rollup

@bors

This comment has been minimized.

Copy link
Contributor

commented Jun 4, 2019

@lzutao: 🔑 Insufficient privileges: not in try users

@bors

This comment has been minimized.

Copy link
Contributor

commented Jun 4, 2019

⌛️ Testing commit d392cb5 with merge 97c9437...

bors added a commit that referenced this pull request Jun 4, 2019

Auto merge of #61454 - lzutao:ice-rotate_left, r=RalfJung
Fix integer overflow in rotate_left

Closes #61406
r? @RalfJung
@bors

This comment has been minimized.

Copy link
Contributor

commented Jun 4, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: RalfJung
Pushing 97c9437 to master...

@bors bors added the merged-by-bors label Jun 4, 2019

@bors bors merged commit d392cb5 into rust-lang:master Jun 4, 2019

2 checks passed

Travis CI - Pull Request Build Passed
Details
homu Test successful
Details

@lzutao lzutao deleted the lzutao:ice-rotate_left branch Jun 5, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.