rust/compiler
bors dbc37a97dc Auto merge of #83307 - richkadel:cov-unused-functions-1.1, r=tmandry
coverage bug fixes and optimization support

Adjusted LLVM codegen for code compiled with `-Zinstrument-coverage` to
address multiple, somewhat related issues.

Fixed a significant flaw in prior coverage solution: Every counter
generated a new counter variable, but there should have only been one
counter variable per function. This appears to have bloated .profraw
files significantly. (For a small program, it increased the size by
about 40%. I have not tested large programs, but there is anecdotal
evidence that profraw files were way too large. This is a good fix,
regardless, but hopefully it also addresses related issues.

Fixes: #82144

Invalid LLVM coverage data produced when compiled with -C opt-level=1

Existing tests now work up to at least `opt-level=3`. This required a
detailed analysis of the LLVM IR, comparisons with Clang C++ LLVM IR
when compiled with coverage, and a lot of trial and error with codegen
adjustments.

The biggest hurdle was figuring out how to continue to support coverage
results for unused functions and generics. Rust's coverage results have
three advantages over Clang's coverage results:

1. Rust's coverage map does not include any overlapping code regions,
   making coverage counting unambiguous.
2. Rust generates coverage results (showing zero counts) for all unused
   functions, including generics. (Clang does not generate coverage for
   uninstantiated template functions.)
3. Rust's unused functions produce minimal stubbed functions in LLVM IR,
   sufficient for including in the coverage results; while Clang must
   generate the complete LLVM IR for each unused function, even though
   it will never be called.

This PR removes the previous hack of attempting to inject coverage into
some other existing function instance, and generates dedicated instances
for each unused function. This change, and a few other adjustments
(similar to what is required for `-C link-dead-code`, but with lower
impact), makes it possible to support LLVM optimizations.

Fixes: #79651

Coverage report: "Unexecuted instantiation:..." for a generic function
from multiple crates

Fixed by removing the aforementioned hack. Some "Unexecuted
instantiation" notices are unavoidable, as explained in the
`used_crate.rs` test, but `-Zinstrument-coverage` has new options to
back off support for either unused generics, or all unused functions,
which avoids the notice, at the cost of less coverage of unused
functions.

Fixes: #82875

Invalid LLVM coverage data produced with crate brotli_decompressor

Fixed by disabling the LLVM function attribute that forces inlining, if
`-Z instrument-coverage` is enabled. This attribute is applied to
Rust functions with `#[inline(always)], and in some cases, the forced
inlining breaks coverage instrumentation and reports.

FYI: `@wesleywiser`

r? `@tmandry`
2021-03-25 05:07:34 +00:00
..
rustc
rustc_apfloat stabilize or_patterns 2021-03-19 19:45:32 -05:00
rustc_arena Rollup merge of #83197 - jyn514:cfg-test-dead-code, r=joshtriplett 2021-03-19 15:03:24 +01:00
rustc_ast Add query for const_param_default 2021-03-23 17:16:20 +00:00
rustc_ast_lowering Add has_default to GenericParamDefKind::Const 2021-03-23 17:16:20 +00:00
rustc_ast_passes progress, stuff compiles now 2021-03-23 17:16:20 +00:00
rustc_ast_pretty Update with comments 2021-03-23 17:16:20 +00:00
rustc_attr stabilize or_patterns 2021-03-19 19:45:32 -05:00
rustc_builtin_macros stabilize or_patterns 2021-03-19 19:45:32 -05:00
rustc_codegen_cranelift update const_eval_resolve 2021-03-20 17:22:24 +01:00
rustc_codegen_llvm Auto merge of #83307 - richkadel:cov-unused-functions-1.1, r=tmandry 2021-03-25 05:07:34 +00:00
rustc_codegen_ssa Auto merge of #83307 - richkadel:cov-unused-functions-1.1, r=tmandry 2021-03-25 05:07:34 +00:00
rustc_data_structures Auto merge of #83273 - cjgillot:endecode, r=michaelwoerister 2021-03-22 12:18:57 +00:00
rustc_driver Auto merge of #83050 - osa1:issue83048, r=matthewjasper 2021-03-24 12:02:13 +00:00
rustc_error_codes progress, stuff compiles now 2021-03-23 17:16:20 +00:00
rustc_errors small cleanups in rustc_errors / emitter 2021-03-24 00:09:11 +01:00
rustc_expand Rollup merge of #83384 - mark-i-m:rename-pat2018, r=joshtriplett 2021-03-23 10:15:43 +09:00
rustc_feature Rollup merge of #83384 - mark-i-m:rename-pat2018, r=joshtriplett 2021-03-23 10:15:43 +09:00
rustc_fs_util
rustc_graphviz
rustc_hir progress, stuff compiles now 2021-03-23 17:16:20 +00:00
rustc_hir_pretty Add has_default to GenericParamDefKind::Const 2021-03-23 17:16:20 +00:00
rustc_incremental Only enable assert_dep_graph when query-dep-graph is enabled. 2021-03-22 19:22:06 +01:00
rustc_index
rustc_infer Update to not have extra match 2021-03-23 20:01:40 +00:00
rustc_interface Auto merge of #83307 - richkadel:cov-unused-functions-1.1, r=tmandry 2021-03-25 05:07:34 +00:00
rustc_lexer
rustc_lint stabilize or_patterns 2021-03-19 19:45:32 -05:00
rustc_lint_defs
rustc_llvm LLVMWrapper: attractive nuisance macros 2021-03-24 14:39:13 -04:00
rustc_macros
rustc_metadata Auto merge of #83307 - richkadel:cov-unused-functions-1.1, r=tmandry 2021-03-25 05:07:34 +00:00
rustc_middle Auto merge of #83307 - richkadel:cov-unused-functions-1.1, r=tmandry 2021-03-25 05:07:34 +00:00
rustc_mir Auto merge of #83307 - richkadel:cov-unused-functions-1.1, r=tmandry 2021-03-25 05:07:34 +00:00
rustc_mir_build Auto merge of #79278 - mark-i-m:stabilize-or-pattern, r=nikomatsakis 2021-03-22 19:48:27 +00:00
rustc_parse Rollup merge of #83384 - mark-i-m:rename-pat2018, r=joshtriplett 2021-03-23 10:15:43 +09:00
rustc_parse_format stabilize or_patterns 2021-03-19 19:45:32 -05:00
rustc_passes Auto merge of #75384 - JulianKnodt:cg_def, r=varkor,lcnr 2021-03-24 04:13:27 +00:00
rustc_plugin_impl
rustc_privacy Update with comments 2021-03-23 17:16:20 +00:00
rustc_query_impl
rustc_query_system Debug-print result when an unstable fingerprint is detected 2021-03-19 21:47:57 -04:00
rustc_resolve progress, stuff compiles now 2021-03-23 17:16:20 +00:00
rustc_save_analysis Add has_default to GenericParamDefKind::Const 2021-03-23 17:16:20 +00:00
rustc_serialize Move raw bytes handling to Encoder/Decoder. 2021-03-19 19:35:22 +01:00
rustc_session Auto merge of #83307 - richkadel:cov-unused-functions-1.1, r=tmandry 2021-03-25 05:07:34 +00:00
rustc_span Add has_default to GenericParamDefKind::Const 2021-03-23 17:16:20 +00:00
rustc_symbol_mangling stabilize or_patterns 2021-03-19 19:45:32 -05:00
rustc_target Allow not emitting uwtable on Android 2021-03-23 04:39:58 +08:00
rustc_trait_selection Use EvaluatedToOkModuloRegions whenever we erase regions 2021-03-24 16:01:37 -04:00
rustc_traits Add has_default to GenericParamDefKind::Const 2021-03-23 17:16:20 +00:00
rustc_ty_utils Don't consider !Unpin references as noalias 2021-03-21 20:10:53 +01:00
rustc_type_ir
rustc_typeck Auto merge of #83307 - richkadel:cov-unused-functions-1.1, r=tmandry 2021-03-25 05:07:34 +00:00