@@ -2,27 +2,38 @@ use crate::traits::*;
2
2
3
3
use rustc_middle:: mir:: coverage:: * ;
4
4
use rustc_middle:: mir:: Coverage ;
5
+ use rustc_middle:: mir:: SourceScope ;
5
6
6
7
use super :: FunctionCx ;
7
8
8
9
impl < ' 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
+
10
21
let Coverage { kind, code_region } = coverage;
11
22
match kind {
12
23
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) {
14
25
// If `set_function_source_hash()` returned true, the coverage map is enabled,
15
26
// so continue adding the counter.
16
27
if let Some ( code_region) = code_region {
17
28
// Note: Some counters do not have code regions, but may still be referenced
18
29
// from expressions. In that case, don't add the counter to the coverage map,
19
30
// 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) ;
21
32
}
22
33
23
- let coverageinfo = bx. tcx ( ) . coverageinfo ( self . instance . def_id ( ) ) ;
34
+ let coverageinfo = bx. tcx ( ) . coverageinfo ( instance. def_id ( ) ) ;
24
35
25
- let fn_name = bx. create_pgo_func_name_var ( self . instance ) ;
36
+ let fn_name = bx. create_pgo_func_name_var ( instance) ;
26
37
let hash = bx. const_u64 ( function_source_hash) ;
27
38
let num_counters = bx. const_u32 ( coverageinfo. num_counters ) ;
28
39
let index = bx. const_u32 ( u32:: from ( id) ) ;
@@ -34,11 +45,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
34
45
}
35
46
}
36
47
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) ;
38
49
}
39
50
CoverageKind :: Unreachable => {
40
51
bx. add_coverage_unreachable (
41
- self . instance ,
52
+ instance,
42
53
code_region. expect ( "unreachable regions always have code regions" ) ,
43
54
) ;
44
55
}
0 commit comments