From f5bd1ca6786dd2e375353b5f031f77eb21727efb Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 7 Dec 2017 12:31:40 +0100 Subject: [PATCH] incr.comp.: Make Span decoding more consistent so it doesn't mess up -Zincremental-verify-ich --- src/librustc_metadata/decoder.rs | 34 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index eb2bcfc93c5..3be99e97223 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -273,25 +273,23 @@ impl<'a, 'tcx> SpecializedDecoder for DecodeContext<'a, 'tcx> { let lo = BytePos::decode(self)?; let hi = BytePos::decode(self)?; + if lo == BytePos(0) && hi == BytePos(0) { + // Don't try to rebase DUMMY_SP. Otherwise it will look like a valid + // Span again. + return Ok(DUMMY_SP) + } + + if hi < lo { + // Consistently map invalid spans to DUMMY_SP. + return Ok(DUMMY_SP) + } + let sess = if let Some(sess) = self.sess { sess } else { bug!("Cannot decode Span without Session.") }; - let (lo, hi) = if lo > hi { - // Currently macro expansion sometimes produces invalid Span values - // where lo > hi. In order not to crash the compiler when trying to - // translate these values, let's transform them into something we - // can handle (and which will produce useful debug locations at - // least some of the time). - // This workaround is only necessary as long as macro expansion is - // not fixed. FIXME(#23480) - (lo, lo) - } else { - (lo, hi) - }; - let imported_filemaps = self.cdata().imported_filemaps(&sess.codemap()); let filemap = { // Optimize for the case that most spans within a translated item @@ -321,6 +319,16 @@ impl<'a, 'tcx> SpecializedDecoder for DecodeContext<'a, 'tcx> { } }; + // Make sure our binary search above is correct. + debug_assert!(lo >= filemap.original_start_pos && + lo <= filemap.original_end_pos); + + if hi < filemap.original_start_pos || hi > filemap.original_end_pos { + // `hi` points to a different FileMap than `lo` which is invalid. + // Again, map invalid Spans to DUMMY_SP. + return Ok(DUMMY_SP) + } + let lo = (lo + filemap.translated_filemap.start_pos) - filemap.original_start_pos; let hi = (hi + filemap.translated_filemap.start_pos) - filemap.original_start_pos;