From 8436cfe71db9a3f0c6b6d8f44fd18b4d6612627a Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Thu, 15 Oct 2020 23:14:50 +0300 Subject: [PATCH] instrument-coverage: try our best to not ICE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit instrument-coverage was ICEing for me on some code, in particular code that had devirtualized paths from standard library. Instrument coverage probably has no bussiness dictating which paths are valid and which aren't so just feed it everything and whatever and let tooling deal with other stuff. For example, with this commit we can generate coverage hitpoints for these interesting paths: * `/rustc/.../library/core/lib.rs` – non-devirtualized path for libcore * `/home/.../src/library/core/lib.rs` – devirtualized version of above * ``, `` and many similar synthetic paths Even if those paths somehow get to the instrumentation pass, I'd much rather get hits for these weird paths and hope some of them work (as would be the case for devirtualized path to libcore), rather than have compilation fail entirely. --- .../rustc_mir/src/transform/instrument_coverage.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_mir/src/transform/instrument_coverage.rs b/compiler/rustc_mir/src/transform/instrument_coverage.rs index babe10a0f14da..6824c73ab60a0 100644 --- a/compiler/rustc_mir/src/transform/instrument_coverage.rs +++ b/compiler/rustc_mir/src/transform/instrument_coverage.rs @@ -22,9 +22,7 @@ use rustc_middle::ty::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_span::def_id::DefId; use rustc_span::source_map::original_sp; -use rustc_span::{ - BytePos, CharPos, FileName, Pos, RealFileName, SourceFile, Span, Symbol, SyntaxContext, -}; +use rustc_span::{BytePos, CharPos, Pos, SourceFile, Span, Symbol, SyntaxContext}; use std::cmp::Ordering; @@ -549,13 +547,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> { let mir_body = &self.mir_body; let body_span = self.body_span(); let source_file = source_map.lookup_source_file(body_span.lo()); - let file_name = match &source_file.name { - FileName::Real(RealFileName::Named(path)) => Symbol::intern(&path.to_string_lossy()), - _ => bug!( - "source_file.name should be a RealFileName, but it was: {:?}", - source_file.name - ), - }; + let file_name = Symbol::intern(&source_file.name.to_string()); debug!("instrumenting {:?}, span: {}", def_id, source_map.span_to_string(body_span));