{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/23115","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/23115/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/23115/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/23115/events","html_url":"https://github.com/rust-lang/rust/issues/23115","id":60101045,"number":23115,"title":"Overflow in span subtraction / astencode","user":{"login":"Manishearth","id":1617736,"avatar_url":"https://avatars.githubusercontent.com/u/1617736?v=3","gravatar_id":"","url":"https://api.github.com/users/Manishearth","html_url":"https://github.com/Manishearth","followers_url":"https://api.github.com/users/Manishearth/followers","following_url":"https://api.github.com/users/Manishearth/following{/other_user}","gists_url":"https://api.github.com/users/Manishearth/gists{/gist_id}","starred_url":"https://api.github.com/users/Manishearth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Manishearth/subscriptions","organizations_url":"https://api.github.com/users/Manishearth/orgs","repos_url":"https://api.github.com/users/Manishearth/repos","events_url":"https://api.github.com/users/Manishearth/events{/privacy}","received_events_url":"https://api.github.com/users/Manishearth/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/I-ICE","name":"I-ICE","color":"e10c02"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":17,"created_at":"2015-03-06T13:23:42Z","updated_at":"2015-03-18T13:06:09Z","closed_at":null,"body":"https://travis-ci.org/GuillaumeGomez/rust-GSL/builds/53335854\r\n\r\n```\r\n\r\nerror: internal compiler error: unexpected panic\r\nnote: the compiler unexpectedly panicked. this is a bug.\r\nnote: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports\r\nnote: run with `RUST_BACKTRACE=1` for a backtrace\r\nthread 'rustc' panicked at 'arithmetic operation overflowed', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libsyntax/codemap.rs:73\r\n\r\nstack backtrace:\r\n   1:     0x7fd52b3bcf6f - sys::backtrace::write::h2f046b875b210aadOBA\r\n   2:     0x7fd52b3e7c82 - panicking::on_panic::h792ac47fb8c07faehHJ\r\n   3:     0x7fd52b31cf2a - rt::unwind::begin_unwind_inner::hbffac672008352c8knJ\r\n   4:     0x7fd52b31d641 - rt::unwind::begin_unwind_fmt::hbe64affaa986f482VlJ\r\n   5:     0x7fd52b3e7807 - rust_begin_unwind\r\n   6:     0x7fd52b433114 - panicking::panic_fmt::h81cd96819f02da8dIZs\r\n   7:     0x7fd52b42f53d - panicking::panic::h8ea414638b29b322UXs\r\n   8:     0x7fd5286f98ac - codemap::BytePos.Sub::sub::h13c0a0f10f07c348YWB\r\n   9:     0x7fd529035ec0 - middle::astencode::DecodeContext<'a, 'b, 'tcx>::tr_span::hdd7910e968f71d01FCa\r\n  10:     0x7fd52904679c - fold::noop_fold_expr::h1258022642513463166\r\n  11:     0x7fd5290464a3 - ptr::P<T>::map::h4462110055941524197\r\n  12:     0x7fd529049c9e - fold::noop_fold_expr::closure.66610\r\n  13:     0x7fd5290469e1 - fold::noop_fold_expr::h1258022642513463166\r\n  14:     0x7fd5290464a3 - ptr::P<T>::map::h4462110055941524197\r\n  15:     0x7fd529049c9e - fold::noop_fold_expr::closure.66610\r\n  16:     0x7fd529046bbe - fold::noop_fold_expr::h1258022642513463166\r\n  17:     0x7fd5290464a3 - ptr::P<T>::map::h4462110055941524197\r\n  18:     0x7fd529049c4b - fold::noop_fold_expr::closure.66605\r\n  19:     0x7fd52904e0a4 - fold::noop_fold_local::closure.66836\r\n  20:     0x7fd52904da97 - fold::noop_fold_decl::closure.66833\r\n  21:     0x7fd52904bc9b - fold::Folder::fold_stmt::closure.66763\r\n  22:     0x7fd52904b553 - fold::noop_fold_block::closure.66714\r\n  23:     0x7fd52904b208 - iter::FlatMap<I, U, F>.Iterator::next::h9223681505759829108\r\n  24:     0x7fd52904a9cf - vec::Vec<T>.FromIterator<T>::from_iter::h13016817088923062838\r\n  25:     0x7fd52904a295 - fold::noop_fold_block::closure.66623\r\n  26:     0x7fd529049e32 - fold::noop_fold_block::h14827012078068820658\r\n  27:     0x7fd529047873 - fold::noop_fold_expr::h1258022642513463166\r\n  28:     0x7fd5290464a3 - ptr::P<T>::map::h4462110055941524197\r\n  29:     0x7fd529049c4b - fold::noop_fold_expr::closure.66605\r\n  30:     0x7fd52904a327 - fold::noop_fold_block::closure.66623\r\n  31:     0x7fd529049e32 - fold::noop_fold_block::h14827012078068820658\r\n  32:     0x7fd529047873 - fold::noop_fold_expr::h1258022642513463166\r\n  33:     0x7fd5290464a3 - ptr::P<T>::map::h4462110055941524197\r\n  34:     0x7fd52904c176 - fold::Folder::fold_stmt::closure.66763\r\n  35:     0x7fd52904b553 - fold::noop_fold_block::closure.66714\r\n  36:     0x7fd52904b208 - iter::FlatMap<I, U, F>.Iterator::next::h9223681505759829108\r\n  37:     0x7fd52904a9cf - vec::Vec<T>.FromIterator<T>::from_iter::h13016817088923062838\r\n  38:     0x7fd52904a295 - fold::noop_fold_block::closure.66623\r\n  39:     0x7fd529049e32 - fold::noop_fold_block::h14827012078068820658\r\n  40:     0x7fd529046f87 - fold::noop_fold_expr::h1258022642513463166\r\n  41:     0x7fd5290464a3 - ptr::P<T>::map::h4462110055941524197\r\n  42:     0x7fd52904bb9b - fold::Folder::fold_stmt::closure.66763\r\n  43:     0x7fd52904b553 - fold::noop_fold_block::closure.66714\r\n  44:     0x7fd52904b208 - iter::FlatMap<I, U, F>.Iterator::next::h9223681505759829108\r\n  45:     0x7fd52904a9cf - vec::Vec<T>.FromIterator<T>::from_iter::h13016817088923062838\r\n  46:     0x7fd52904a295 - fold::noop_fold_block::closure.66623\r\n  47:     0x7fd529049e32 - fold::noop_fold_block::h14827012078068820658\r\n  48:     0x7fd529047873 - fold::noop_fold_expr::h1258022642513463166\r\n  49:     0x7fd5290464a3 - ptr::P<T>::map::h4462110055941524197\r\n  50:     0x7fd529049c4b - fold::noop_fold_expr::closure.66605\r\n  51:     0x7fd52904a327 - fold::noop_fold_block::closure.66623\r\n  52:     0x7fd529049e32 - fold::noop_fold_block::h14827012078068820658\r\n  53:     0x7fd529069f57 - fold::noop_fold_method::closure.67217\r\n  54:     0x7fd5290696c5 - fold::noop_fold_method::h2920979874065131956\r\n  55:     0x7fd529038abb - middle::astencode::decode_inlined_item::h674342a5ff4e1a27Pqa\r\n  56:     0x7fd52a9f81ff - trans::inline::instantiate_inline::closure.39610\r\n  57:     0x7fd529427c2b - metadata::decoder::maybe_get_item_ast::h6b38702aa8f07983PDi\r\n  58:     0x7fd52922aec6 - metadata::csearch::maybe_get_item_ast::hf5174e6ae59eb7b5o3k\r\n  59:     0x7fd52a9f6a5d - trans::inline::instantiate_inline::h6a8d7203fac7c299bid\r\n  60:     0x7fd52aa45d85 - trans::callee::trans_fn_ref_with_substs::h85a6252d422343b2qng\r\n  61:     0x7fd52aa4452e - trans::callee::trans_fn_ref::h7eebc758d7f24cf00bg\r\n  62:     0x7fd52aa5b344 - trans::meth::trans_method_callee::h175c0aff2b6fe67998x\r\n  63:     0x7fd52aa59a19 - trans::callee::trans_call_inner::h18244630176801372264\r\n  64:     0x7fd52aa638e9 - trans::expr::trans_rvalue_dps_unadjusted::h62a8f691df1cee3cqCi\r\n  65:     0x7fd52aa154e6 - trans::expr::trans_into::h3bbb0e210c9fb401Vph\r\n  66:     0x7fd52aa14684 - trans::controlflow::trans_stmt_semi::hd74052e320e3d8baK6d\r\n  67:     0x7fd52aa15fc0 - trans::controlflow::trans_block::h4b526e186a057814x7d\r\n  68:     0x7fd52aa640de - trans::expr::trans_rvalue_dps_unadjusted::h62a8f691df1cee3cqCi\r\n  69:     0x7fd52aa154e6 - trans::expr::trans_into::h3bbb0e210c9fb401Vph\r\n  70:     0x7fd52aa14684 - trans::controlflow::trans_stmt_semi::hd74052e320e3d8baK6d\r\n  71:     0x7fd52aa15fc0 - trans::controlflow::trans_block::h4b526e186a057814x7d\r\n  72:     0x7fd52aaed3b1 - trans::base::trans_closure::h194b7ad0474e43a46mt\r\n  73:     0x7fd52a9fe948 - trans::base::trans_fn::h5416ef5d9cea730bZxt\r\n  74:     0x7fd52a9fa6e1 - trans::base::trans_item::h2af153dd6f7fd52bRVt\r\n  75:     0x7fd52aaf674c - trans::base::trans_crate::h5cb53f6b3e2377862Ru\r\n  76:     0x7fd52b9f7613 - driver::phase_4_translate_to_llvm::h60575195b9fa298dENa\r\n  77:     0x7fd52b9d305b - driver::compile_input::h9772b425fd1776fdNba\r\n  78:     0x7fd52ba97697 - run_compiler::h17c28dbe4dd58e3bV5b\r\n  79:     0x7fd52ba952c9 - thunk::F.Invoke<A, R>::invoke::h3041729087284544127\r\n  80:     0x7fd52ba93f40 - rt::unwind::try::try_fn::h11775082019993619070\r\n  81:     0x7fd52b457e38 - rust_try_inner\r\n  82:     0x7fd52b457e25 - rust_try\r\n  83:     0x7fd52ba946df - thunk::F.Invoke<A, R>::invoke::h10556879288050829464\r\n  84:     0x7fd52b3d29b5 - sys::thread::thread_start::hfe8c2cac3ec4afcdr8E\r\n  85:     0x7fd52520fe99 - start_thread\r\n  86:     0x7fd52af8a4bc - <unknown>\r\n```\r\n\r\nOffending code:\r\n\r\n```\r\n\r\nimpl Sub for BytePos {\r\n    type Output = BytePos;\r\n\r\n    fn sub(self, rhs: BytePos) -> BytePos {\r\n        BytePos((self.to_usize() - rhs.to_usize()) as u32)\r\n    }\r\n}\r\n```\r\n\r\nand the code calling it:\r\n\r\n```\r\n    pub fn tr_span(&self, span: Span) -> Span {\r\n        let imported_filemaps = &self.cdata.codemap_import_info[..];\r\n\r\n        let filemap_index = {\r\n            // Optimize for the case that most spans within a translated item\r\n            // originate from the same filemap.\r\n            let last_filemap_index = self.last_filemap_index.get();\r\n\r\n            if span.lo >= imported_filemaps[last_filemap_index].original_start_pos &&\r\n               span.hi <= imported_filemaps[last_filemap_index].original_end_pos {\r\n                last_filemap_index\r\n            } else {\r\n                let mut a = 0;\r\n                let mut b = imported_filemaps.len();\r\n\r\n                while b - a > 1 {\r\n                    let m = (a + b) / 2;\r\n                    if imported_filemaps[m].original_start_pos > span.lo {\r\n                        b = m;\r\n                    } else {\r\n                        a = m;\r\n                    }\r\n                }\r\n\r\n                self.last_filemap_index.set(a);\r\n                a\r\n            }\r\n        };\r\n\r\n        let lo = (span.lo - imported_filemaps[filemap_index].original_start_pos) +\r\n                  imported_filemaps[filemap_index].translated_filemap.start_pos;\r\n        let hi = (span.hi - imported_filemaps[filemap_index].original_start_pos) +\r\n                  imported_filemaps[filemap_index].translated_filemap.start_pos;\r\n\r\n        codemap::mk_sp(lo, hi)\r\n    }\r\n```\r\n\r\n\r\nWe might want a bounds check there (resolving to 0?), but there seems to be something broken in the astencode code too.\r\n\r\n\r\ncc @GuillaumeGomez @pnkfelix \r\n"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/82962161","html_url":"https://github.com/rust-lang/rust/issues/23115#issuecomment-82962161","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/23115","id":82962161,"user":{"login":"pnkfelix","id":173127,"avatar_url":"https://avatars.githubusercontent.com/u/173127?v=3","gravatar_id":"","url":"https://api.github.com/users/pnkfelix","html_url":"https://github.com/pnkfelix","followers_url":"https://api.github.com/users/pnkfelix/followers","following_url":"https://api.github.com/users/pnkfelix/following{/other_user}","gists_url":"https://api.github.com/users/pnkfelix/gists{/gist_id}","starred_url":"https://api.github.com/users/pnkfelix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnkfelix/subscriptions","organizations_url":"https://api.github.com/users/pnkfelix/orgs","repos_url":"https://api.github.com/users/pnkfelix/repos","events_url":"https://api.github.com/users/pnkfelix/events{/privacy}","received_events_url":"https://api.github.com/users/pnkfelix/received_events","type":"User","site_admin":false},"created_at":"2015-03-18T13:06:09Z","updated_at":"2015-03-18T13:06:09Z","body":"@Manishearth I don't think that's a good idea for the short term.  I tried to put in such an assertion some time ago, and its a real rat hole."}}