@@ -2,27 +2,38 @@ use crate::traits::*;
22
33use rustc_middle:: mir:: coverage:: * ;
44use rustc_middle:: mir:: Coverage ;
5+ use rustc_middle:: mir:: SourceScope ;
56
67use super :: FunctionCx ;
78
89impl < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > FunctionCx < ' a , ' tcx , Bx > {
9- pub fn codegen_coverage ( & self , bx : & mut Bx , coverage : Coverage ) {
10+ pub fn codegen_coverage ( & self , bx : & mut Bx , coverage : Coverage , scope : SourceScope ) {
11+ // Determine the instance that coverage data was originally generated for.
12+ let scope_data = & self . mir . source_scopes [ scope] ;
13+ let instance = if let Some ( ( inlined_instance, _) ) = scope_data. inlined {
14+ self . monomorphize ( inlined_instance)
15+ } else if let Some ( inlined_scope) = scope_data. inlined_parent_scope {
16+ self . monomorphize ( self . mir . source_scopes [ inlined_scope] . inlined . unwrap ( ) . 0 )
17+ } else {
18+ self . instance
19+ } ;
20+
1021 let Coverage { kind, code_region } = coverage;
1122 match kind {
1223 CoverageKind :: Counter { function_source_hash, id } => {
13- if bx. set_function_source_hash ( self . instance , function_source_hash) {
24+ if bx. set_function_source_hash ( instance, function_source_hash) {
1425 // If `set_function_source_hash()` returned true, the coverage map is enabled,
1526 // so continue adding the counter.
1627 if let Some ( code_region) = code_region {
1728 // Note: Some counters do not have code regions, but may still be referenced
1829 // from expressions. In that case, don't add the counter to the coverage map,
1930 // but do inject the counter intrinsic.
20- bx. add_coverage_counter ( self . instance , id, code_region) ;
31+ bx. add_coverage_counter ( instance, id, code_region) ;
2132 }
2233
23- let coverageinfo = bx. tcx ( ) . coverageinfo ( self . instance . def_id ( ) ) ;
34+ let coverageinfo = bx. tcx ( ) . coverageinfo ( instance. def_id ( ) ) ;
2435
25- let fn_name = bx. create_pgo_func_name_var ( self . instance ) ;
36+ let fn_name = bx. create_pgo_func_name_var ( instance) ;
2637 let hash = bx. const_u64 ( function_source_hash) ;
2738 let num_counters = bx. const_u32 ( coverageinfo. num_counters ) ;
2839 let index = bx. const_u32 ( u32:: from ( id) ) ;
@@ -34,11 +45,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
3445 }
3546 }
3647 CoverageKind :: Expression { id, lhs, op, rhs } => {
37- bx. add_coverage_counter_expression ( self . instance , id, lhs, op, rhs, code_region) ;
48+ bx. add_coverage_counter_expression ( instance, id, lhs, op, rhs, code_region) ;
3849 }
3950 CoverageKind :: Unreachable => {
4051 bx. add_coverage_unreachable (
41- self . instance ,
52+ instance,
4253 code_region. expect ( "unreachable regions always have code regions" ) ,
4354 ) ;
4455 }
0 commit comments