rust/compiler
Rich Kadel bcf755562a 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.
2021-03-19 17:11:50 -07:00
..
rustc Rollup merge of #82642 - sfackler:jemalloc-zone, r=pnkfelix 2021-03-08 13:13:22 +01:00
rustc_apfloat bumped smallvec deps 2021-02-14 18:03:11 +03:00
rustc_arena Rollup merge of #83197 - jyn514:cfg-test-dead-code, r=joshtriplett 2021-03-19 15:03:24 +01:00
rustc_ast Auto merge of #82868 - petrochenkov:bto, r=estebank 2021-03-18 05:27:26 +00:00
rustc_ast_lowering hir: Preserve used syntax in TyKind::TraitObject 2021-03-18 03:02:32 +03:00
rustc_ast_passes ast/hir: Rename field-related structures 2021-03-16 11:41:24 +03:00
rustc_ast_pretty ast: Reduce size of ExprKind by boxing fields of ExprKind::Struct 2021-03-16 11:41:24 +03:00
rustc_attr Auto merge of #71481 - estebank:inherit-stability, r=nikomatsakis 2021-03-05 05:28:07 +00:00
rustc_builtin_macros Rollup merge of #82270 - asquared31415:asm-syntax-directive-errors, r=nagisa 2021-03-18 00:28:06 +01:00
rustc_codegen_cranelift s/ConstantSource/ConstantKind/ 2021-03-15 12:06:52 +00:00
rustc_codegen_llvm coverage bug fixes and optimization support 2021-03-19 17:11:50 -07:00
rustc_codegen_ssa coverage bug fixes and optimization support 2021-03-19 17:11:50 -07:00
rustc_data_structures Rollup merge of #83197 - jyn514:cfg-test-dead-code, r=joshtriplett 2021-03-19 15:03:24 +01:00
rustc_driver Add rustc_interface::interface::Config::parse_sess_created 2021-03-15 18:24:58 +08:00
rustc_error_codes Rollup merge of #80527 - jyn514:rustdoc-lints, r=GuillaumeGomez 2021-03-04 20:01:01 +09:00
rustc_errors Remove unnecessary forward_inner_docs hack 2021-03-17 09:52:45 -04:00
rustc_expand Extend proc_macro_back_compat lint to actix-web 2021-03-18 12:09:14 -04:00
rustc_feature Replace type_alias_impl_trait by min_type_alias_impl_trait with no actual changes in behaviour 2021-03-15 17:32:43 +00:00
rustc_fs_util
rustc_graphviz
rustc_hir hir: Preserve used syntax in TyKind::TraitObject 2021-03-18 03:02:32 +03:00
rustc_hir_pretty hir: Preserve used syntax in TyKind::TraitObject 2021-03-18 03:02:32 +03:00
rustc_incremental ast/hir: Rename field-related structures 2021-03-16 11:41:24 +03:00
rustc_index Remove useless Clone bound in IndexVec. 2021-03-09 18:51:36 +01:00
rustc_infer hir: Preserve used syntax in TyKind::TraitObject 2021-03-18 03:02:32 +03:00
rustc_interface coverage bug fixes and optimization support 2021-03-19 17:11:50 -07:00
rustc_lexer
rustc_lint Rollup merge of #83216 - jyn514:register-tool, r=petrochenkov 2021-03-18 00:28:14 +01:00
rustc_lint_defs Introduce proc_macro_back_compat lint, and emit for time-macros-impl 2021-03-14 21:31:46 -04:00
rustc_llvm Auto merge of #83044 - kubo39:set-llvm-code-model, r=nikic 2021-03-14 11:46:57 +00:00
rustc_macros Add inlining. 2021-03-11 12:24:43 +01:00
rustc_metadata coverage bug fixes and optimization support 2021-03-19 17:11:50 -07:00
rustc_middle coverage bug fixes and optimization support 2021-03-19 17:11:50 -07:00
rustc_mir coverage bug fixes and optimization support 2021-03-19 17:11:50 -07:00
rustc_mir_build Replace closures_captures and upvar_capture with closure_min_captures 2021-03-18 20:45:49 -04:00
rustc_parse Auto merge of #76447 - pickfire:async-pub, r=estebank 2021-03-18 02:32:39 +00:00
rustc_parse_format
rustc_passes Auto merge of #82951 - sexxi-goose:wr-mir-replace-methods2, r=nikomatsakis 2021-03-19 18:23:44 +00:00
rustc_plugin_impl Remove hir::Item::attrs. 2021-03-09 19:27:50 +01:00
rustc_privacy ast/hir: Rename field-related structures 2021-03-16 11:41:24 +03:00
rustc_query_impl Auto merge of #82936 - oli-obk:valtree, r=RalfJung,lcnr,matthewjasper 2021-03-16 22:42:56 +00:00
rustc_query_system Auto merge of #82999 - cuviper:rustc-rayon-0.3.1, r=Mark-Simulacrum 2021-03-15 08:49:25 +00:00
rustc_resolve hir: Preserve used syntax in TyKind::TraitObject 2021-03-18 03:02:32 +03:00
rustc_save_analysis ast/hir: Rename field-related structures 2021-03-16 11:41:24 +03:00
rustc_serialize Update the bootstrap compiler 2021-02-20 17:19:30 -05:00
rustc_session coverage bug fixes and optimization support 2021-03-19 17:11:50 -07:00
rustc_span Rollup merge of #83197 - jyn514:cfg-test-dead-code, r=joshtriplett 2021-03-19 15:03:24 +01:00
rustc_symbol_mangling rustc_target: add "unwind" payloads to Abi 2021-03-09 14:38:29 -05:00
rustc_target riscvgc-unknown-none-elf use lp64d ABI 2021-03-17 10:45:58 -04:00
rustc_trait_selection Fix use of bare trait objects everywhere 2021-03-18 02:18:58 +03:00
rustc_traits Fix use of bare trait objects everywhere 2021-03-18 02:18:58 +03:00
rustc_ty_utils Auto merge of #82159 - BoxyUwU:uwu, r=varkor 2021-02-24 21:54:52 +00:00
rustc_type_ir New pass to deduplicate blocks 2021-02-21 21:51:54 +01:00
rustc_typeck coverage bug fixes and optimization support 2021-03-19 17:11:50 -07:00