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

Panic on accessing codemap of size 0 #26504

Closed
cassiersg opened this issue Jun 22, 2015 · 2 comments
Closed

Panic on accessing codemap of size 0 #26504

cassiersg opened this issue Jun 22, 2015 · 2 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@cassiersg
Copy link

Using rustc_driver::run_compiler(["empty_file.rs"], ...), the compilation is stopped after parsing.
The codemap is retrieved, and the call to lookup_char_pos panics when we visit the AST:

impl visit::Visitor for FmtVisitor {
    fn visit_mod(&mut self, m: &'v ast::Mod, s: Span, _: ast::NodeId) {
        if self codemap.lookup_char_pos(s.lo).file.name
[...]

I'm wondering if it's an unexpected behavior or if this situation violates an invariant of codemap.

Backtrace:

thread '<main>' panicked at 'position 0 does not resolve to a source location', ../src/libsyntax/codemap.rs:908
stack backtrace:
   1:     0x7fb91319f92e - sys::backtrace::write::he24e072826f78dbbpqs
   2:     0x7fb9131a79ec - panicking::on_panic::hfe8dee88ad5f1f8f69w
   3:     0x7fb91316a53e - rt::unwind::begin_unwind_inner::h30a8282e6074626cKPw
   4:     0x7fb91316b26c - rt::unwind::begin_unwind_fmt::h0d67ce05a74a7ba4QOw
   5:     0x7fb913987313 - codemap::CodeMap::lookup_filemap_idx::hdb5a6d4b9a382f2by4z
   6:     0x7fb913986e11 - codemap::CodeMap::lookup_char_pos::hcfccdd83504b914fJJz
   7:     0x7fb9152b24c8 - visitor::FmtVisitor<'a>.visit..Visitor<'v>::visit_mod::hb8cb15535f0f5ffbZUa
                        at /home/cassiersg/rustfmt/src/visitor.rs:249
   8:     0x7fb9152f174b - visit::walk_crate::h11272277405317629321
                        at ../src/libsyntax/visit.rs:152
   9:     0x7fb9152f1489 - fmt_ast::h0042e145cf43e2281Jd
                        at /home/cassiersg/rustfmt/src/lib.rs:165
  10:     0x7fb9152fbc3d - RustFmtCalls.CompilerCalls<'a>::build_controller::closure.12943
                        at /home/cassiersg/rustfmt/src/lib.rs:309
  11:     0x7fb914ce8a88 - driver::compile_input::hc2338ec138000972Tba
  12:     0x7fb914dc67d3 - run_compiler::h64b107044b742926x7b
  13:     0x7fb9152fc5d2 - run::h1118ec9f2f6cbfc82Wd
                        at /home/cassiersg/rustfmt/src/lib.rs:340
  14:     0x7fb91525a5c3 - main::h78aa2f0fe725515fkaa
                        at bin/rustfmt.rs:27
  15:     0x7fb91321f758 - rust_try_inner
  16:     0x7fb91321f745 - rust_try
  17:     0x7fb9131a9527 - rt::lang_start::hdadb5fc58c5eeff334w
  18:     0x7fb91526159b - main
  19:     0x7fb91282078f - __libc_start_main
  20:     0x7fb91525a2a8 - _start
  21:                0x0 - <unknown>

rustc:

$ rustc --version --verbose
rustc 1.2.0-nightly (9ad0063a1 2015-06-20)
binary: rustc
commit-hash: 9ad0063a1772edca3299e2dc76187bbfa74e8b16
commit-date: 2015-06-20
host: x86_64-unknown-linux-gnu
release: 1.2.0-nightly

cc nrc/rustfmt#115

@Stebalien
Copy link
Contributor

Sounds like #23301.

@steveklabnik steveklabnik added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jun 23, 2015
nrc added a commit to nrc/rust that referenced this issue Jul 21, 2015
So if a filemap's last byte is at position n in the codemap, then n+1 will not refer to any filemap, and the next filemap will begin an n+2.

This is useful for empty files, it means that every file (even empty ones) has a byte in the codemap.

Closes rust-lang#23301, rust-lang#26504
@marcusklaas
Copy link
Contributor

This has been resolved, I think.

cc @cassiersg @nrc @steveklabnik

@nrc nrc closed this as completed Sep 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

5 participants