diff options
| author | Michael Woerister <michaelwoerister@posteo> | 2017-12-07 12:31:40 +0100 |
|---|---|---|
| committer | Michael Woerister <michaelwoerister@posteo> | 2017-12-08 10:02:26 +0100 |
| commit | f5bd1ca6786dd2e375353b5f031f77eb21727efb (patch) | |
| tree | 83cd495911cedff4ecdb1b5d6679dbf4eb9c3e60 | |
| parent | 1c0e611dff9090b06f69a177721e01d24edc82b7 (diff) | |
| download | rust-f5bd1ca6786dd2e375353b5f031f77eb21727efb.tar.gz rust-f5bd1ca6786dd2e375353b5f031f77eb21727efb.zip | |
incr.comp.: Make Span decoding more consistent so it doesn't mess up -Zincremental-verify-ich
| -rw-r--r-- | src/librustc_metadata/decoder.rs | 34 |
1 files 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<Span> 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<Span> 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; |
