Skip to content

Code that misuses the write! macro hangs rustc for 1 minute and then SIGILLs (OOM) #19163

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

Closed
japaric opened this issue Nov 20, 2014 · 8 comments
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Comments

@japaric
Copy link
Member

japaric commented Nov 20, 2014

STR

fn main() {
    let mut v = vec![];
    write!(&v, "Hello world");
}

Output

$ time rustc write.rs
<std macros>:3:24: 3:14 error: cannot borrow immutable dereference of `&`-pointer as mutable
<std macros>:3         let dst = &mut *$dst;
[2]    2803 illegal hardware instruction (core dumped)  rustc write.rs
rustc write.rs  58.66s user 4.81s system 99% cpu 1:03.86 total

Backtrace

#0  0x00007ffff7351560 in oom::h6671a0e79ac45df3RTa () from /usr/lib64/librustrt-4e7c5e5c.so
#1  0x00007ffff499c535 in ?? () from /usr/lib64/libsyntax-4e7c5e5c.so
#2  0x00007ffff4a3fd27 in ?? () from /usr/lib64/libsyntax-4e7c5e5c.so
#3  0x00007ffff4a3b083 in diagnostic::EmitterWriter.Emitter::emit::h8944016a574210b0lrG ()
   from /usr/lib64/libsyntax-4e7c5e5c.so
#4  0x00007ffff4a398f9 in diagnostic::Handler::emit::hef6d94e096dac3f1F8F ()
   from /usr/lib64/libsyntax-4e7c5e5c.so
#5  0x00007ffff4a0c3ed in diagnostic::SpanHandler::span_err::he4174115bd82cc5fEWF ()
   from /usr/lib64/libsyntax-4e7c5e5c.so
#6  0x00007ffff5a77fea in middle::borrowck::BorrowckCtxt$LT$$x27a$C$$x20$x27tcx$GT$::report::h3050434306868883rEh () from /usr/lib64/librustc-4e7c5e5c.so
#7  0x00007ffff5a7d524 in middle::borrowck::gather_loans::GatherLoanCtxt$LT$$x27a$C$$x20$x27tcx$GT$.euv..Delegate$LT$$x27tcx$GT$::borrow::hd3a8e951ce2e3945bef () from /usr/lib64/librustc-4e7c5e5c.so
#8  0x00007ffff5a87421 in ?? () from /usr/lib64/librustc-4e7c5e5c.so
#9  0x00007ffff5a83d44 in ?? () from /usr/lib64/librustc-4e7c5e5c.so
#10 0x00007ffff5a830d0 in ?? () from /usr/lib64/librustc-4e7c5e5c.so
#11 0x00007ffff5a838d7 in ?? () from /usr/lib64/librustc-4e7c5e5c.so
#12 0x00007ffff5a876a9 in ?? () from /usr/lib64/librustc-4e7c5e5c.so
#13 0x00007ffff5a83091 in ?? () from /usr/lib64/librustc-4e7c5e5c.so
#14 0x00007ffff5a7ad31 in middle::borrowck::gather_loans::gather_loans_in_fn::ha2f120a3c6b6b70b96e ()
   from /usr/lib64/librustc-4e7c5e5c.so
#15 0x00007ffff5a9c574 in ?? () from /usr/lib64/librustc-4e7c5e5c.so
#16 0x00007ffff5a9961d in ?? () from /usr/lib64/librustc-4e7c5e5c.so
#17 0x00007ffff5a9b666 in ?? () from /usr/lib64/librustc-4e7c5e5c.so
#18 0x00007ffff5a9a2f8 in ?? () from /usr/lib64/librustc-4e7c5e5c.so
#19 0x00007ffff5a99cc5 in middle::borrowck::check_crate::h7908f5f01a09671eOPg ()
   from /usr/lib64/librustc-4e7c5e5c.so
#20 0x00007ffff76a9917 in ?? () from /usr/lib64/librustc_trans-4e7c5e5c.so
#21 0x00007ffff7840568 in driver::driver::phase_3_run_analysis_passes::he238813c217c3b94efS ()
   from /usr/lib64/librustc_trans-4e7c5e5c.so
#22 0x00007ffff7833238 in driver::driver::compile_input::h117f94c1b348a398YVR ()
   from /usr/lib64/librustc_trans-4e7c5e5c.so
#23 0x00007ffff78b7cd7 in ?? () from /usr/lib64/librustc_trans-4e7c5e5c.so
#24 0x00007ffff78b62fc in ?? () from /usr/lib64/librustc_trans-4e7c5e5c.so
#25 0x00007ffff76c2f78 in ?? () from /usr/lib64/librustc_trans-4e7c5e5c.so
#26 0x00007ffff76c2e83 in ?? () from /usr/lib64/librustc_trans-4e7c5e5c.so
#27 0x00007ffff7bd6be2 in ?? () from /usr/lib64/libnative-4e7c5e5c.so
#28 0x00007ffff7390fec in ?? () from /usr/lib64/librustrt-4e7c5e5c.so
#29 0x00007ffff7390fd6 in rust_try () from /usr/lib64/librustrt-4e7c5e5c.so
#30 0x00007ffff733f843 in unwind::try::h03ead95328113b2fIZc () from /usr/lib64/librustrt-4e7c5e5c.so
#31 0x00007ffff733f70c in task::Task::run::hed7dc0cf620a0172y5b () from /usr/lib64/librustrt-4e7c5e5c.so
#32 0x00007ffff7bd69e7 in ?? () from /usr/lib64/libnative-4e7c5e5c.so
#33 0x00007ffff7340f35 in ?? () from /usr/lib64/librustrt-4e7c5e5c.so
#34 0x00007ffff1e0e294 in start_thread () from /lib64/libpthread.so.0
#35 0x00007ffff70181ed in clone () from /lib64/libc.so.6

Version

1d81776

Can anyone reproduce? I find this bizarre...

cc @alexcrichton @jakub- @sfackler

@barosl
Copy link
Contributor

barosl commented Nov 20, 2014

Same here. The error message is completely different from that of the old compiler.

  • 336349c 2014-11-17 20:37:19 +0000:
test.rs:3:12: 3:14 error: type `&collections::vec::Vec<_>` does not implement any method in scope named `write_fmt`
test.rs:3     write!(&v, "Hello world");
  • 399ff25 2014-11-20 00:27:07 +0000:
<std macros>:3:24: 3:14 error: cannot borrow immutable dereference of `&`-pointer as mutable
<std macros>:3         let dst = &mut *$dst;

@barosl
Copy link
Contributor

barosl commented Nov 20, 2014

This is a duplicate of #19155, by the way.

@sfackler
Copy link
Member

I don't think this is a dup of that. The compiler doesn't OOM in my bug.

@barosl
Copy link
Contributor

barosl commented Nov 20, 2014

Oh, then it is a separate one. To be accurate, my test above also consumed the entire memory and died.

@kmcallister
Copy link
Contributor

Fail to reproduce on Linux with rustc 1.0.0-dev (4e4e8cf 2015-01-24 22:14:14 +0000).

@kmcallister kmcallister added the I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. label Jan 28, 2015
@japaric
Copy link
Member Author

japaric commented Jan 28, 2015

The write! macro has changed since I opened this issue. I sort-of replicated the old write! macro but couldn't reproduce the bug:

macro_rules! mywrite {
    ($dst:expr, $($arg:tt)*) => ({
        let dst = &mut *$dst;  //~ error: cannot borrow immutable borrowed content as mutable
        (|&mut: args| { dst.write_fmt(args) })(format_args!($($arg)*))
    })
}

fn main() {
    let mut v = vec![];
    mywrite!(&v, "Hello world");
}

We should add a test to avoid regressions.

@sfackler sfackler added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jan 28, 2015
@ghost
Copy link

ghost commented Jan 28, 2015

The subtlety with write! is that it's defined in an external crate so a potential test should ideally reflect that. :)

@kmcallister
Copy link
Contributor

Still no hang with

// mywrite.rs
#![crate_type="lib"]

#[macro_export]
macro_rules! mywrite {
    ($dst:expr, $($arg:tt)*) => ({
        let dst = &mut *$dst;  //~ error: cannot borrow immutable borrowed content as mutable
        (|&mut: args| { dst.write_fmt(args) })(format_args!($($arg)*))
    })
}

and

// main.rs
$ cat main.rs
#[macro_use] extern crate mywrite;

fn main() {
    let mut v = vec![];
    mywrite!(&v, "Hello world");
}

Result:

$ rustc --version
rustc 1.0.0-dev (4e4e8cff1 2015-01-24 22:14:14 +0000)

$ rustc -L . mywrite.rs 

$ time rustc -L . main.rs 
<mywrite macros>:3:17: 5:16 error: cannot borrow immutable borrowed content as mutable
<mywrite macros>:3 let dst = & mut * $ dst ; ( | & mut : args | { dst . write_fmt ( args ) } ) (
<mywrite macros>:4 format_args ! ( $ ( $ arg ) * ) ) } )
<mywrite macros>:1:1: 4:38 note: in expansion of mywrite!
main.rs:5:5: 5:33 note: expansion site
error: aborting due to previous error

real    0m0.066s
user    0m0.056s
sys     0m0.008s

@bors bors closed this as completed in 2193857 May 4, 2015
lnicola pushed a commit to lnicola/rust that referenced this issue Feb 17, 2025
fix: Stabilize sort order of `related_tests`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

No branches or pull requests

4 participants