-
Notifications
You must be signed in to change notification settings - Fork 13k
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
RefCell complains two mutable borrows present when only one exist on armv7-unknown-linux-gnueabihf #40593
Comments
This may be related to rust-openssl/issues/597. It would appear like dropping of values is broken in the nightly and beta toolchain: This works: let mutex = Mutex::new(());
let mut guard = None;
guard = Some(mutex.lock().unwrap());
drop(guard.take().unwrap());
mutex.try_lock().unwrap(); // locks as expected but this fails: let mutex = Mutex::new(());
let mut guard = None;
guard = Some(mutex.lock().unwrap());
drop(guard.take()); // unwrap() removed
mutex.try_lock().unwrap(); // panics "WouldBlock" This seem a rather new issue, in nightly-2017-03-01 it still worked. (May also work in few of the newer versions, haven't had time to try all of them.) |
Tried a few more nightly snapshots nightly-2017-03-04 is the first affected version, nightly-2017-03-03 works flawlessly. |
@pgerber Where can you find the nightly snapshots? I tried downloading them with rustup.rs, but it said older ones couldn't be found. |
@MJDSys This worked for me:
|
#40133 looks like the main diff. between the 2 versions. Self-assigning. |
The first example is optimized out completely on my machine (using |
@arielb1 Did you run that on an armv7 machine, or on a x86(_64) machine? It seems something really weird is happening in the compiler. I'm working with a simpler example (see end of this post). A compiler on x86_64 produces a MIR representation that seems to make sense (dropping the option, and then the inner type). However with an armv7 compiler, it doesn't drop the option, but tries to drop the T (while inside the option). I'm not familiar with what the correct representation is, but that is the big difference I see on armv7. And just to be clear, I need to use a native compiler to see that difference. Cross-compiling the source file does not produce the difference. If it would help, I'll try to post the different outputs from MIR comparing before/after March 4 between x86_64 and armv7. I also don't think it's an issue in the MIR optimization passes, as when I dump the MIR using -Z dump-mir=all, that difference is always present. I'm doing all my testing right now with debug builds, but my initial testing before reporting the bug happened with both debug and release. New example: #[deny(warnings)]
struct T{}
impl Drop for T {
fn drop(&mut self) {
//println!("dropped");
panic!(false);
}
}
fn main() {
{
Some(T{});
}
} |
I am using an ARM compiler (rustc 1.17.0-nightly (b1e3176 2017-03-03) aka the Mar 4 nightly) in an x86_64 machine using qemu, which seems not to reproduce the bug. I don't have an ARM machine handy right now, |
Ah. The problem was that I was using the Correct "at-typeck" MIR looks like this:
Incorrect "at-typeck" MIR looks like this:
|
Looking at direct builder output: BAD:
GOOD:
|
debugging. It seems that after #40178, type contents is miscompiled somehow. |
Reverting things did fix things for me. This is however, a miscompile, so problems are to be expected. |
Did you revert it on top of master, or on top of the nightly build from March 4th? |
On top of a559452 |
Looks like an LLVM bug, unless we have some "hidden" UB somewhere: For some reason, this IR:
Lowers the last call/or/select as
And a |
@arielb1 Could you post the entire file, or give me steps to generate/investigate it locally? I'm new to playing with rustc's codebase and would like to take a deeper look/follow along at home. |
This looks like an LLVM bug, not a rustc bug. |
@arielb1 That's fine, I'm just trying to learn more about the stack. If you have a reference for how you got that, I'm happy to read that as well. |
Minified LLVM bug - will report to LLVM after seeing the status on 4.0:
|
Reported as http://bugs.llvm.org/show_bug.cgi?id=32379. |
triage: P-high |
update LLVM with fix for PR32379 Fixes #40593. The "root" codegen bug fixed here is that, when generating ARM code, unpatched LLVM 3.9/3.9.1 miscompiles bit operations in rare circumstances - this can cause user code compiled via LLVM (through both `rustc` and `clang`) to subtly return incorrect results - for more details, see the test in this PR or in the LLVM rare report. One effect of that LLVM bug is that `rustc` 1.17 (and possibly other versions) is miscompiled on ARM. The code generated by a miscompiled `rustc` lacks destructor calls in many circumstances. Users who run an affected/miscompiled `rustc` - 1.17 or above - on an ARM build machine will be affected by the (fairly blatant) missing destructor bug, regardless of the target architecture (this includes the official `1.17.0-beta.1`, `1.17.0-beta.2`, and some official 1.17/1.18 nightlies). Users who use an affected LLVM (that's any unpatched LLVM 3.9/3.9.1), whether through `rustc` (in any version that supports 3.9 - that's 1.12 or above) or through `clang`, who compile code to an ARM target architecture might be affected by the (fairly hard to hit) bit operation bug, regardless of the build machine. Distributors and user who want to compile rustc using their own LLVM should apply the [patch](llvm-mirror/llvm@cdc303e) to avoid miscompilations. r? @alexcrichton Beta-nominating because regression (rustc 1.16 is not blatantly miscompiled). This also picks a fix for the (MSVC-affecting) PR29151.
When running the program at: https://is.gd/XHVVMt on my Chromebook (an Asus C201p) with the latest nightly compiler, I get the following error (RUST_BACKTRACE=1):
This doesn't occur on the latest stable compiler, and started sometime around March 12. This doesn't happen on my AMD 64bit desktop, nor on playground. Both debug and release builds are affected.
Code:
(note the extra scopes don't affect the behaviour.)
The text was updated successfully, but these errors were encountered: