@@ -13,7 +13,7 @@ use rustc_ast::ast;
13
13
use rustc_codegen_ssa:: base:: { compare_simd_types, to_immediate, wants_msvc_seh} ;
14
14
use rustc_codegen_ssa:: common:: span_invalid_monomorphization_error;
15
15
use rustc_codegen_ssa:: common:: { IntPredicate , TypeKind } ;
16
- use rustc_codegen_ssa:: coverageinfo:: ExprKind ;
16
+ use rustc_codegen_ssa:: coverageinfo;
17
17
use rustc_codegen_ssa:: glue;
18
18
use rustc_codegen_ssa:: mir:: operand:: { OperandRef , OperandValue } ;
19
19
use rustc_codegen_ssa:: mir:: place:: PlaceRef ;
@@ -93,64 +93,64 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
93
93
let mut is_codegen_intrinsic = true ;
94
94
// Set `is_codegen_intrinsic` to `false` to bypass `codegen_intrinsic_call()`.
95
95
96
- if self . tcx . sess . opts . debugging_opts . instrument_coverage {
97
- // If the intrinsic is from the local MIR, add the coverage information to the Codegen
98
- // context, to be encoded into the local crate's coverage map.
99
- if caller_instance. def_id ( ) . is_local ( ) {
100
- // FIXME(richkadel): Make sure to add coverage analysis tests on a crate with
101
- // external crate dependencies, where:
102
- // 1. Both binary and dependent crates are compiled with `-Zinstrument-coverage`
103
- // 2. Only binary is compiled with `-Zinstrument-coverage`
104
- // 3. Only dependent crates are compiled with `-Zinstrument-coverage`
105
- match intrinsic {
106
- sym:: count_code_region => {
107
- use coverage:: count_code_region_args:: * ;
108
- self . add_counter_region (
109
- caller_instance,
110
- op_to_u64 ( & args[ FUNCTION_SOURCE_HASH ] ) ,
111
- op_to_u32 ( & args[ COUNTER_ID ] ) ,
112
- op_to_u32 ( & args[ START_BYTE_POS ] ) ,
113
- op_to_u32 ( & args[ END_BYTE_POS ] ) ,
114
- ) ;
115
- }
116
- sym:: coverage_counter_add | sym:: coverage_counter_subtract => {
117
- use coverage:: coverage_counter_expression_args:: * ;
118
- self . add_counter_expression_region (
119
- caller_instance,
120
- op_to_u32 ( & args[ EXPRESSION_ID ] ) ,
121
- op_to_u32 ( & args[ LEFT_ID ] ) ,
122
- if intrinsic == sym:: coverage_counter_add {
123
- ExprKind :: Add
124
- } else {
125
- ExprKind :: Subtract
126
- } ,
127
- op_to_u32 ( & args[ RIGHT_ID ] ) ,
128
- op_to_u32 ( & args[ START_BYTE_POS ] ) ,
129
- op_to_u32 ( & args[ END_BYTE_POS ] ) ,
130
- ) ;
131
- }
132
- sym:: coverage_unreachable => {
133
- use coverage:: coverage_unreachable_args:: * ;
134
- self . add_unreachable_region (
135
- caller_instance,
136
- op_to_u32 ( & args[ START_BYTE_POS ] ) ,
137
- op_to_u32 ( & args[ END_BYTE_POS ] ) ,
138
- ) ;
139
- }
140
- _ => { }
141
- }
96
+ // FIXME(richkadel): Make sure to add coverage analysis tests on a crate with
97
+ // external crate dependencies, where:
98
+ // 1. Both binary and dependent crates are compiled with `-Zinstrument-coverage`
99
+ // 2. Only binary is compiled with `-Zinstrument-coverage`
100
+ // 3. Only dependent crates are compiled with `-Zinstrument-coverage`
101
+ match intrinsic {
102
+ sym:: count_code_region => {
103
+ use coverage:: count_code_region_args:: * ;
104
+ self . add_counter_region (
105
+ caller_instance,
106
+ op_to_u64 ( & args[ FUNCTION_SOURCE_HASH ] ) ,
107
+ op_to_u32 ( & args[ COUNTER_ID ] ) ,
108
+ coverageinfo:: Region :: new (
109
+ op_to_str_slice ( & args[ FILE_NAME ] ) ,
110
+ op_to_u32 ( & args[ START_LINE ] ) ,
111
+ op_to_u32 ( & args[ START_COL ] ) ,
112
+ op_to_u32 ( & args[ END_LINE ] ) ,
113
+ op_to_u32 ( & args[ END_COL ] ) ,
114
+ ) ,
115
+ ) ;
142
116
}
143
-
144
- // Only the `count_code_region` coverage intrinsic is translated into an actual LLVM
145
- // intrinsic call (local or not); otherwise, set `is_codegen_intrinsic` to `false`.
146
- match intrinsic {
147
- sym:: coverage_counter_add
148
- | sym:: coverage_counter_subtract
149
- | sym:: coverage_unreachable => {
150
- is_codegen_intrinsic = false ;
151
- }
152
- _ => { }
117
+ sym:: coverage_counter_add | sym:: coverage_counter_subtract => {
118
+ is_codegen_intrinsic = false ;
119
+ use coverage:: coverage_counter_expression_args:: * ;
120
+ self . add_counter_expression_region (
121
+ caller_instance,
122
+ op_to_u32 ( & args[ EXPRESSION_ID ] ) ,
123
+ op_to_u32 ( & args[ LEFT_ID ] ) ,
124
+ if intrinsic == sym:: coverage_counter_add {
125
+ coverageinfo:: ExprKind :: Add
126
+ } else {
127
+ coverageinfo:: ExprKind :: Subtract
128
+ } ,
129
+ op_to_u32 ( & args[ RIGHT_ID ] ) ,
130
+ coverageinfo:: Region :: new (
131
+ op_to_str_slice ( & args[ FILE_NAME ] ) ,
132
+ op_to_u32 ( & args[ START_LINE ] ) ,
133
+ op_to_u32 ( & args[ START_COL ] ) ,
134
+ op_to_u32 ( & args[ END_LINE ] ) ,
135
+ op_to_u32 ( & args[ END_COL ] ) ,
136
+ ) ,
137
+ ) ;
153
138
}
139
+ sym:: coverage_unreachable => {
140
+ is_codegen_intrinsic = false ;
141
+ use coverage:: coverage_unreachable_args:: * ;
142
+ self . add_unreachable_region (
143
+ caller_instance,
144
+ coverageinfo:: Region :: new (
145
+ op_to_str_slice ( & args[ FILE_NAME ] ) ,
146
+ op_to_u32 ( & args[ START_LINE ] ) ,
147
+ op_to_u32 ( & args[ START_COL ] ) ,
148
+ op_to_u32 ( & args[ END_LINE ] ) ,
149
+ op_to_u32 ( & args[ END_COL ] ) ,
150
+ ) ,
151
+ ) ;
152
+ }
153
+ _ => { }
154
154
}
155
155
is_codegen_intrinsic
156
156
}
@@ -215,9 +215,6 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
215
215
self . call ( llfn, & [ ] , None )
216
216
}
217
217
sym:: count_code_region => {
218
- // FIXME(richkadel): The current implementation assumes the MIR for the given
219
- // caller_instance represents a single function. Validate and/or correct if inlining
220
- // and/or monomorphization invalidates these assumptions.
221
218
let coverageinfo = tcx. coverageinfo ( caller_instance. def_id ( ) ) ;
222
219
let mangled_fn = tcx. symbol_name ( caller_instance) ;
223
220
let ( mangled_fn_name, _len_val) = self . const_str ( Symbol :: intern ( mangled_fn. name ) ) ;
@@ -2283,6 +2280,10 @@ fn float_type_width(ty: Ty<'_>) -> Option<u64> {
2283
2280
}
2284
2281
}
2285
2282
2283
+ fn op_to_str_slice < ' tcx > ( op : & Operand < ' tcx > ) -> & ' tcx str {
2284
+ Operand :: value_from_const ( op) . try_to_str_slice ( ) . expect ( "Value is &str" )
2285
+ }
2286
+
2286
2287
fn op_to_u32 < ' tcx > ( op : & Operand < ' tcx > ) -> u32 {
2287
2288
Operand :: scalar_from_const ( op) . to_u32 ( ) . expect ( "Scalar is u32" )
2288
2289
}
0 commit comments