diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index e74d66a859926..c9bc858b8e918 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2193,7 +2193,7 @@ impl<'test> TestCx<'test> { || self.is_vxworks_pure_static() || self.config.target.contains("bpf") || !self.config.target_cfg().dynamic_linking - || self.config.mode == RunCoverage + || matches!(self.config.mode, CoverageMap | RunCoverage) { // We primarily compile all auxiliary libraries as dynamic libraries // to avoid code size bloat and large binaries as much as possible @@ -2481,9 +2481,9 @@ impl<'test> TestCx<'test> { RunCoverage => { rustc.arg("-Cinstrument-coverage"); // Coverage reports are sometimes sensitive to optimizations, - // and the current snapshots assume no optimization unless + // and the current snapshots assume `opt-level=2` unless // overridden by `compile-flags`. - rustc.arg("-Copt-level=0"); + rustc.arg("-Copt-level=2"); } RunPassValgrind | Pretty | DebugInfo | Codegen | Rustdoc | RustdocJson | RunMake | CodegenUnits | JsDocTest | Assembly => { diff --git a/tests/coverage-map/README.md b/tests/coverage-map/README.md index 60d1352cd64f1..146fbff5b204d 100644 --- a/tests/coverage-map/README.md +++ b/tests/coverage-map/README.md @@ -1,4 +1,4 @@ -The tests in `./status-quo` were copied from `tests/run-coverage` in order to +Many of these tests were copied from `tests/run-coverage` in order to capture the current behavior of the instrumentor on non-trivial programs. The actual mappings have not been closely inspected. diff --git a/tests/coverage-map/status-quo/abort.cov-map b/tests/coverage-map/abort.cov-map similarity index 100% rename from tests/coverage-map/status-quo/abort.cov-map rename to tests/coverage-map/abort.cov-map diff --git a/tests/coverage-map/status-quo/abort.rs b/tests/coverage-map/abort.rs similarity index 100% rename from tests/coverage-map/status-quo/abort.rs rename to tests/coverage-map/abort.rs diff --git a/tests/coverage-map/status-quo/assert.cov-map b/tests/coverage-map/assert.cov-map similarity index 100% rename from tests/coverage-map/status-quo/assert.cov-map rename to tests/coverage-map/assert.cov-map diff --git a/tests/coverage-map/status-quo/assert.rs b/tests/coverage-map/assert.rs similarity index 100% rename from tests/coverage-map/status-quo/assert.rs rename to tests/coverage-map/assert.rs diff --git a/tests/coverage-map/status-quo/async.cov-map b/tests/coverage-map/async.cov-map similarity index 100% rename from tests/coverage-map/status-quo/async.cov-map rename to tests/coverage-map/async.cov-map diff --git a/tests/coverage-map/status-quo/async.rs b/tests/coverage-map/async.rs similarity index 100% rename from tests/coverage-map/status-quo/async.rs rename to tests/coverage-map/async.rs diff --git a/tests/coverage-map/status-quo/async2.cov-map b/tests/coverage-map/async2.cov-map similarity index 100% rename from tests/coverage-map/status-quo/async2.cov-map rename to tests/coverage-map/async2.cov-map diff --git a/tests/coverage-map/status-quo/async2.rs b/tests/coverage-map/async2.rs similarity index 100% rename from tests/coverage-map/status-quo/async2.rs rename to tests/coverage-map/async2.rs diff --git a/tests/coverage-map/auxiliary/inline_always_with_dead_code.rs b/tests/coverage-map/auxiliary/inline_always_with_dead_code.rs new file mode 100644 index 0000000000000..9dc50dae25ae2 --- /dev/null +++ b/tests/coverage-map/auxiliary/inline_always_with_dead_code.rs @@ -0,0 +1,22 @@ +// compile-flags: -Cinstrument-coverage -Ccodegen-units=4 -Copt-level=0 + +#![allow(dead_code)] + +mod foo { + #[inline(always)] + pub fn called() {} + + fn uncalled() {} +} + +pub mod bar { + pub fn call_me() { + super::foo::called(); + } +} + +pub mod baz { + pub fn call_me() { + super::foo::called(); + } +} diff --git a/tests/coverage-map/auxiliary/unused_mod_helper.rs b/tests/coverage-map/auxiliary/unused_mod_helper.rs new file mode 100644 index 0000000000000..88c5dac65cb50 --- /dev/null +++ b/tests/coverage-map/auxiliary/unused_mod_helper.rs @@ -0,0 +1,4 @@ +#[allow(dead_code)] +pub fn never_called_function() { + println!("I am never called"); +} diff --git a/tests/coverage-map/auxiliary/used_crate.rs b/tests/coverage-map/auxiliary/used_crate.rs new file mode 100644 index 0000000000000..c086ef21e1a9f --- /dev/null +++ b/tests/coverage-map/auxiliary/used_crate.rs @@ -0,0 +1,103 @@ +#![allow(unused_assignments, unused_variables)] +// Verify that coverage works with optimizations: +// compile-flags: -C opt-level=3 + +use std::fmt::Debug; + +pub fn used_function() { + // Initialize test constants in a way that cannot be determined at compile time, to ensure + // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from + // dependent conditions. + let is_true = std::env::args().len() == 1; + let mut countdown = 0; + if is_true { + countdown = 10; + } + use_this_lib_crate(); +} + +pub fn used_only_from_bin_crate_generic_function(arg: T) { + println!("used_only_from_bin_crate_generic_function with {:?}", arg); +} +// Expect for above function: `Unexecuted instantiation` (see below) +pub fn used_only_from_this_lib_crate_generic_function(arg: T) { + println!("used_only_from_this_lib_crate_generic_function with {:?}", arg); +} + +pub fn used_from_bin_crate_and_lib_crate_generic_function(arg: T) { + println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg); +} + +pub fn used_with_same_type_from_bin_crate_and_lib_crate_generic_function(arg: T) { + println!("used_with_same_type_from_bin_crate_and_lib_crate_generic_function with {:?}", arg); +} + +pub fn unused_generic_function(arg: T) { + println!("unused_generic_function with {:?}", arg); +} + +pub fn unused_function() { + let is_true = std::env::args().len() == 1; + let mut countdown = 2; + if !is_true { + countdown = 20; + } +} + +#[allow(dead_code)] +fn unused_private_function() { + let is_true = std::env::args().len() == 1; + let mut countdown = 2; + if !is_true { + countdown = 20; + } +} + +fn use_this_lib_crate() { + used_from_bin_crate_and_lib_crate_generic_function("used from library used_crate.rs"); + used_with_same_type_from_bin_crate_and_lib_crate_generic_function( + "used from library used_crate.rs", + ); + let some_vec = vec![5, 6, 7, 8]; + used_only_from_this_lib_crate_generic_function(some_vec); + used_only_from_this_lib_crate_generic_function("used ONLY from library used_crate.rs"); +} + +// FIXME(#79651): "Unexecuted instantiation" errors appear in coverage results, +// for example: +// +// | Unexecuted instantiation: used_crate::used_only_from_bin_crate_generic_function::<_> +// +// These notices appear when `llvm-cov` shows instantiations. This may be a +// default option, but it can be suppressed with: +// +// ```shell +// $ `llvm-cov show --show-instantiations=0 ...` +// ``` +// +// The notice is triggered because the function is unused by the library itself, +// and when the library is compiled, a synthetic function is generated, so +// unused function coverage can be reported. Coverage can be skipped for unused +// generic functions with: +// +// ```shell +// $ `rustc -Zunstable-options -C instrument-coverage=except-unused-generics ...` +// ``` +// +// Even though this function is used by `uses_crate.rs` (and +// counted), with substitutions for `T`, those instantiations are only generated +// when the generic function is actually used (from the binary, not from this +// library crate). So the test result shows coverage for all instantiated +// versions and their generic type substitutions, plus the `Unexecuted +// instantiation` message for the non-substituted version. This is valid, but +// unfortunately a little confusing. +// +// The library crate has its own coverage map, and the only way to show unused +// coverage of a generic function is to include the generic function in the +// coverage map, marked as an "unused function". If the library were used by +// another binary that never used this generic function, then it would be valid +// to show the unused generic, with unknown substitution (`_`). +// +// The alternative is to exclude all generics from being included in the "unused +// functions" list, which would then omit coverage results for +// `unused_generic_function()`, below. diff --git a/tests/coverage-map/auxiliary/used_inline_crate.rs b/tests/coverage-map/auxiliary/used_inline_crate.rs new file mode 100644 index 0000000000000..e8929de6b360a --- /dev/null +++ b/tests/coverage-map/auxiliary/used_inline_crate.rs @@ -0,0 +1,85 @@ +#![allow(unused_assignments, unused_variables)] +// Verify that coverage works with optimizations: +// compile-flags: -C opt-level=3 + +use std::fmt::Debug; + +pub fn used_function() { + // Initialize test constants in a way that cannot be determined at compile time, to ensure + // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from + // dependent conditions. + let is_true = std::env::args().len() == 1; + let mut countdown = 0; + if is_true { + countdown = 10; + } + use_this_lib_crate(); +} + +#[inline(always)] +pub fn used_inline_function() { + // Initialize test constants in a way that cannot be determined at compile time, to ensure + // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from + // dependent conditions. + let is_true = std::env::args().len() == 1; + let mut countdown = 0; + if is_true { + countdown = 10; + } + use_this_lib_crate(); +} + +#[inline(always)] +pub fn used_only_from_bin_crate_generic_function(arg: T) { + println!("used_only_from_bin_crate_generic_function with {:?}", arg); +} +// Expect for above function: `Unexecuted instantiation` (see notes in `used_crate.rs`) + +#[inline(always)] +pub fn used_only_from_this_lib_crate_generic_function(arg: T) { + println!("used_only_from_this_lib_crate_generic_function with {:?}", arg); +} + +#[inline(always)] +pub fn used_from_bin_crate_and_lib_crate_generic_function(arg: T) { + println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg); +} + +#[inline(always)] +pub fn used_with_same_type_from_bin_crate_and_lib_crate_generic_function(arg: T) { + println!("used_with_same_type_from_bin_crate_and_lib_crate_generic_function with {:?}", arg); +} + +#[inline(always)] +pub fn unused_generic_function(arg: T) { + println!("unused_generic_function with {:?}", arg); +} + +#[inline(always)] +pub fn unused_function() { + let is_true = std::env::args().len() == 1; + let mut countdown = 2; + if !is_true { + countdown = 20; + } +} + +#[inline(always)] +#[allow(dead_code)] +fn unused_private_function() { + let is_true = std::env::args().len() == 1; + let mut countdown = 2; + if !is_true { + countdown = 20; + } +} + +fn use_this_lib_crate() { + used_from_bin_crate_and_lib_crate_generic_function("used from library used_crate.rs"); + used_with_same_type_from_bin_crate_and_lib_crate_generic_function( + "used from library used_crate.rs", + ); + let some_vec = vec![5, 6, 7, 8]; + used_only_from_this_lib_crate_generic_function(some_vec); + used_only_from_this_lib_crate_generic_function("used ONLY from library used_crate.rs"); +} diff --git a/tests/coverage-map/status-quo/bad_counter_ids.cov-map b/tests/coverage-map/bad_counter_ids.cov-map similarity index 100% rename from tests/coverage-map/status-quo/bad_counter_ids.cov-map rename to tests/coverage-map/bad_counter_ids.cov-map diff --git a/tests/coverage-map/status-quo/bad_counter_ids.rs b/tests/coverage-map/bad_counter_ids.rs similarity index 100% rename from tests/coverage-map/status-quo/bad_counter_ids.rs rename to tests/coverage-map/bad_counter_ids.rs diff --git a/tests/coverage-map/status-quo/closure.cov-map b/tests/coverage-map/closure.cov-map similarity index 100% rename from tests/coverage-map/status-quo/closure.cov-map rename to tests/coverage-map/closure.cov-map diff --git a/tests/coverage-map/status-quo/closure.rs b/tests/coverage-map/closure.rs similarity index 100% rename from tests/coverage-map/status-quo/closure.rs rename to tests/coverage-map/closure.rs diff --git a/tests/coverage-map/status-quo/closure_bug.cov-map b/tests/coverage-map/closure_bug.cov-map similarity index 100% rename from tests/coverage-map/status-quo/closure_bug.cov-map rename to tests/coverage-map/closure_bug.cov-map diff --git a/tests/coverage-map/status-quo/closure_bug.rs b/tests/coverage-map/closure_bug.rs similarity index 100% rename from tests/coverage-map/status-quo/closure_bug.rs rename to tests/coverage-map/closure_bug.rs diff --git a/tests/coverage-map/status-quo/closure_macro.cov-map b/tests/coverage-map/closure_macro.cov-map similarity index 100% rename from tests/coverage-map/status-quo/closure_macro.cov-map rename to tests/coverage-map/closure_macro.cov-map diff --git a/tests/coverage-map/status-quo/closure_macro.rs b/tests/coverage-map/closure_macro.rs similarity index 100% rename from tests/coverage-map/status-quo/closure_macro.rs rename to tests/coverage-map/closure_macro.rs diff --git a/tests/coverage-map/status-quo/closure_macro_async.cov-map b/tests/coverage-map/closure_macro_async.cov-map similarity index 100% rename from tests/coverage-map/status-quo/closure_macro_async.cov-map rename to tests/coverage-map/closure_macro_async.cov-map diff --git a/tests/coverage-map/status-quo/closure_macro_async.rs b/tests/coverage-map/closure_macro_async.rs similarity index 100% rename from tests/coverage-map/status-quo/closure_macro_async.rs rename to tests/coverage-map/closure_macro_async.rs diff --git a/tests/coverage-map/status-quo/conditions.cov-map b/tests/coverage-map/conditions.cov-map similarity index 100% rename from tests/coverage-map/status-quo/conditions.cov-map rename to tests/coverage-map/conditions.cov-map diff --git a/tests/coverage-map/status-quo/conditions.rs b/tests/coverage-map/conditions.rs similarity index 100% rename from tests/coverage-map/status-quo/conditions.rs rename to tests/coverage-map/conditions.rs diff --git a/tests/coverage-map/status-quo/continue.cov-map b/tests/coverage-map/continue.cov-map similarity index 100% rename from tests/coverage-map/status-quo/continue.cov-map rename to tests/coverage-map/continue.cov-map diff --git a/tests/coverage-map/status-quo/continue.rs b/tests/coverage-map/continue.rs similarity index 100% rename from tests/coverage-map/status-quo/continue.rs rename to tests/coverage-map/continue.rs diff --git a/tests/coverage-map/status-quo/coroutine.cov-map b/tests/coverage-map/coroutine.cov-map similarity index 100% rename from tests/coverage-map/status-quo/coroutine.cov-map rename to tests/coverage-map/coroutine.cov-map diff --git a/tests/coverage-map/status-quo/coroutine.rs b/tests/coverage-map/coroutine.rs similarity index 100% rename from tests/coverage-map/status-quo/coroutine.rs rename to tests/coverage-map/coroutine.rs diff --git a/tests/coverage-map/status-quo/dead_code.cov-map b/tests/coverage-map/dead_code.cov-map similarity index 100% rename from tests/coverage-map/status-quo/dead_code.cov-map rename to tests/coverage-map/dead_code.cov-map diff --git a/tests/coverage-map/status-quo/dead_code.rs b/tests/coverage-map/dead_code.rs similarity index 100% rename from tests/coverage-map/status-quo/dead_code.rs rename to tests/coverage-map/dead_code.rs diff --git a/tests/coverage-map/status-quo/drop_trait.cov-map b/tests/coverage-map/drop_trait.cov-map similarity index 100% rename from tests/coverage-map/status-quo/drop_trait.cov-map rename to tests/coverage-map/drop_trait.cov-map diff --git a/tests/coverage-map/status-quo/drop_trait.rs b/tests/coverage-map/drop_trait.rs similarity index 100% rename from tests/coverage-map/status-quo/drop_trait.rs rename to tests/coverage-map/drop_trait.rs diff --git a/tests/coverage-map/status-quo/generics.cov-map b/tests/coverage-map/generics.cov-map similarity index 100% rename from tests/coverage-map/status-quo/generics.cov-map rename to tests/coverage-map/generics.cov-map diff --git a/tests/coverage-map/status-quo/generics.rs b/tests/coverage-map/generics.rs similarity index 100% rename from tests/coverage-map/status-quo/generics.rs rename to tests/coverage-map/generics.rs diff --git a/tests/coverage-map/if.cov-map b/tests/coverage-map/if.cov-map index 3cedb5ffbecb1..391a69e0e821d 100644 --- a/tests/coverage-map/if.cov-map +++ b/tests/coverage-map/if.cov-map @@ -1,15 +1,15 @@ Function name: if::main -Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 03, 01, 02, 0c, 05, 02, 0d, 02, 06, 02, 02, 06, 00, 07, 07, 01, 05, 01, 02] +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 03, 01, 12, 10, 05, 13, 05, 05, 06, 02, 05, 06, 00, 07, 07, 01, 01, 00, 02] Number of files: 1 - file 0 => global file 1 Number of expressions: 2 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) - expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) Number of file 0 mappings: 4 -- Code(Counter(0)) at (prev + 3, 1) to (start + 2, 12) -- Code(Counter(1)) at (prev + 2, 13) to (start + 2, 6) -- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7) +- Code(Counter(0)) at (prev + 3, 1) to (start + 18, 16) +- Code(Counter(1)) at (prev + 19, 5) to (start + 5, 6) +- Code(Expression(0, Sub)) at (prev + 5, 6) to (start + 0, 7) = (c0 - c1) -- Code(Expression(1, Add)) at (prev + 1, 5) to (start + 1, 2) +- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2) = (c1 + (c0 - c1)) diff --git a/tests/coverage-map/if.rs b/tests/coverage-map/if.rs index ed3f69bdc98d2..8ad5042ff7baf 100644 --- a/tests/coverage-map/if.rs +++ b/tests/coverage-map/if.rs @@ -1,9 +1,28 @@ -// compile-flags: --edition=2021 +#![allow(unused_assignments, unused_variables)] fn main() { - let cond = std::env::args().len() == 1; - if cond { - println!("true"); + // Initialize test constants in a way that cannot be determined at compile time, to ensure + // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from + // dependent conditions. + let + is_true + = + std::env::args().len() + == + 1 + ; + let + mut + countdown + = + 0 + ; + if + is_true + { + countdown + = + 10 + ; } - println!("done"); } diff --git a/tests/coverage-map/status-quo/if_else.cov-map b/tests/coverage-map/if_else.cov-map similarity index 100% rename from tests/coverage-map/status-quo/if_else.cov-map rename to tests/coverage-map/if_else.cov-map diff --git a/tests/coverage-map/status-quo/if_else.rs b/tests/coverage-map/if_else.rs similarity index 100% rename from tests/coverage-map/status-quo/if_else.rs rename to tests/coverage-map/if_else.rs diff --git a/tests/coverage-map/status-quo/inline-dead.cov-map b/tests/coverage-map/inline-dead.cov-map similarity index 100% rename from tests/coverage-map/status-quo/inline-dead.cov-map rename to tests/coverage-map/inline-dead.cov-map diff --git a/tests/coverage-map/status-quo/inline-dead.rs b/tests/coverage-map/inline-dead.rs similarity index 100% rename from tests/coverage-map/status-quo/inline-dead.rs rename to tests/coverage-map/inline-dead.rs diff --git a/tests/coverage-map/status-quo/inline.cov-map b/tests/coverage-map/inline.cov-map similarity index 100% rename from tests/coverage-map/status-quo/inline.cov-map rename to tests/coverage-map/inline.cov-map diff --git a/tests/coverage-map/status-quo/inline.rs b/tests/coverage-map/inline.rs similarity index 100% rename from tests/coverage-map/status-quo/inline.rs rename to tests/coverage-map/inline.rs diff --git a/tests/coverage-map/status-quo/inner_items.cov-map b/tests/coverage-map/inner_items.cov-map similarity index 100% rename from tests/coverage-map/status-quo/inner_items.cov-map rename to tests/coverage-map/inner_items.cov-map diff --git a/tests/coverage-map/status-quo/inner_items.rs b/tests/coverage-map/inner_items.rs similarity index 100% rename from tests/coverage-map/status-quo/inner_items.rs rename to tests/coverage-map/inner_items.rs diff --git a/tests/coverage-map/status-quo/issue-83601.cov-map b/tests/coverage-map/issue-83601.cov-map similarity index 100% rename from tests/coverage-map/status-quo/issue-83601.cov-map rename to tests/coverage-map/issue-83601.cov-map diff --git a/tests/coverage-map/status-quo/issue-83601.rs b/tests/coverage-map/issue-83601.rs similarity index 100% rename from tests/coverage-map/status-quo/issue-83601.rs rename to tests/coverage-map/issue-83601.rs diff --git a/tests/coverage-map/status-quo/issue-84561.cov-map b/tests/coverage-map/issue-84561.cov-map similarity index 100% rename from tests/coverage-map/status-quo/issue-84561.cov-map rename to tests/coverage-map/issue-84561.cov-map diff --git a/tests/coverage-map/status-quo/issue-84561.rs b/tests/coverage-map/issue-84561.rs similarity index 100% rename from tests/coverage-map/status-quo/issue-84561.rs rename to tests/coverage-map/issue-84561.rs diff --git a/tests/coverage-map/issue-85461.cov-map b/tests/coverage-map/issue-85461.cov-map new file mode 100644 index 0000000000000..d1c449b9a355e --- /dev/null +++ b/tests/coverage-map/issue-85461.cov-map @@ -0,0 +1,8 @@ +Function name: issue_85461::main +Raw bytes (9): 0x[01, 01, 00, 01, 01, 08, 01, 03, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 8, 1) to (start + 3, 2) + diff --git a/tests/coverage-map/issue-85461.rs b/tests/coverage-map/issue-85461.rs new file mode 100644 index 0000000000000..9d4c90a827eeb --- /dev/null +++ b/tests/coverage-map/issue-85461.rs @@ -0,0 +1,11 @@ +// Regression test for #85461: MSVC sometimes fail to link with dead code and #[inline(always)] + +// aux-build:inline_always_with_dead_code.rs +extern crate inline_always_with_dead_code; + +use inline_always_with_dead_code::{bar, baz}; + +fn main() { + bar::call_me(); + baz::call_me(); +} diff --git a/tests/coverage-map/status-quo/issue-93054.cov-map b/tests/coverage-map/issue-93054.cov-map similarity index 100% rename from tests/coverage-map/status-quo/issue-93054.cov-map rename to tests/coverage-map/issue-93054.cov-map diff --git a/tests/coverage-map/status-quo/issue-93054.rs b/tests/coverage-map/issue-93054.rs similarity index 100% rename from tests/coverage-map/status-quo/issue-93054.rs rename to tests/coverage-map/issue-93054.rs diff --git a/tests/coverage-map/status-quo/lazy_boolean.cov-map b/tests/coverage-map/lazy_boolean.cov-map similarity index 100% rename from tests/coverage-map/status-quo/lazy_boolean.cov-map rename to tests/coverage-map/lazy_boolean.cov-map diff --git a/tests/coverage-map/status-quo/lazy_boolean.rs b/tests/coverage-map/lazy_boolean.rs similarity index 100% rename from tests/coverage-map/status-quo/lazy_boolean.rs rename to tests/coverage-map/lazy_boolean.rs diff --git a/tests/coverage-map/status-quo/loop_break_value.cov-map b/tests/coverage-map/loop_break_value.cov-map similarity index 100% rename from tests/coverage-map/status-quo/loop_break_value.cov-map rename to tests/coverage-map/loop_break_value.cov-map diff --git a/tests/coverage-map/status-quo/loop_break_value.rs b/tests/coverage-map/loop_break_value.rs similarity index 100% rename from tests/coverage-map/status-quo/loop_break_value.rs rename to tests/coverage-map/loop_break_value.rs diff --git a/tests/coverage-map/status-quo/loops_branches.cov-map b/tests/coverage-map/loops_branches.cov-map similarity index 100% rename from tests/coverage-map/status-quo/loops_branches.cov-map rename to tests/coverage-map/loops_branches.cov-map diff --git a/tests/coverage-map/status-quo/loops_branches.rs b/tests/coverage-map/loops_branches.rs similarity index 100% rename from tests/coverage-map/status-quo/loops_branches.rs rename to tests/coverage-map/loops_branches.rs diff --git a/tests/coverage-map/status-quo/match_or_pattern.cov-map b/tests/coverage-map/match_or_pattern.cov-map similarity index 100% rename from tests/coverage-map/status-quo/match_or_pattern.cov-map rename to tests/coverage-map/match_or_pattern.cov-map diff --git a/tests/coverage-map/status-quo/match_or_pattern.rs b/tests/coverage-map/match_or_pattern.rs similarity index 100% rename from tests/coverage-map/status-quo/match_or_pattern.rs rename to tests/coverage-map/match_or_pattern.rs diff --git a/tests/coverage-map/status-quo/nested_loops.cov-map b/tests/coverage-map/nested_loops.cov-map similarity index 100% rename from tests/coverage-map/status-quo/nested_loops.cov-map rename to tests/coverage-map/nested_loops.cov-map diff --git a/tests/coverage-map/status-quo/nested_loops.rs b/tests/coverage-map/nested_loops.rs similarity index 100% rename from tests/coverage-map/status-quo/nested_loops.rs rename to tests/coverage-map/nested_loops.rs diff --git a/tests/coverage-map/status-quo/no_cov_crate.cov-map b/tests/coverage-map/no_cov_crate.cov-map similarity index 100% rename from tests/coverage-map/status-quo/no_cov_crate.cov-map rename to tests/coverage-map/no_cov_crate.cov-map diff --git a/tests/coverage-map/status-quo/no_cov_crate.rs b/tests/coverage-map/no_cov_crate.rs similarity index 100% rename from tests/coverage-map/status-quo/no_cov_crate.rs rename to tests/coverage-map/no_cov_crate.rs diff --git a/tests/coverage-map/status-quo/overflow.cov-map b/tests/coverage-map/overflow.cov-map similarity index 89% rename from tests/coverage-map/status-quo/overflow.cov-map rename to tests/coverage-map/overflow.cov-map index bfffd9b2ab515..39a5c05f879ad 100644 --- a/tests/coverage-map/status-quo/overflow.cov-map +++ b/tests/coverage-map/overflow.cov-map @@ -1,5 +1,5 @@ Function name: overflow::main -Raw bytes (65): 0x[01, 01, 08, 01, 1b, 05, 1f, 09, 0d, 03, 11, 16, 05, 03, 11, 05, 1f, 09, 0d, 09, 01, 0f, 01, 01, 1b, 03, 02, 0b, 00, 18, 16, 01, 0c, 00, 1a, 05, 00, 1b, 03, 0a, 12, 03, 13, 00, 20, 09, 00, 21, 03, 0a, 0d, 03, 0a, 00, 0b, 1b, 01, 09, 00, 17, 11, 02, 05, 01, 02] +Raw bytes (65): 0x[01, 01, 08, 01, 1b, 05, 1f, 09, 0d, 03, 11, 16, 05, 03, 11, 05, 1f, 09, 0d, 09, 01, 10, 01, 01, 1b, 03, 02, 0b, 00, 18, 16, 01, 0c, 00, 1a, 05, 00, 1b, 03, 0a, 12, 03, 13, 00, 20, 09, 00, 21, 03, 0a, 0d, 03, 0a, 00, 0b, 1b, 01, 09, 00, 17, 11, 02, 05, 01, 02] Number of files: 1 - file 0 => global file 1 Number of expressions: 8 @@ -12,7 +12,7 @@ Number of expressions: 8 - expression 6 operands: lhs = Counter(1), rhs = Expression(7, Add) - expression 7 operands: lhs = Counter(2), rhs = Counter(3) Number of file 0 mappings: 9 -- Code(Counter(0)) at (prev + 15, 1) to (start + 1, 27) +- Code(Counter(0)) at (prev + 16, 1) to (start + 1, 27) - Code(Expression(0, Add)) at (prev + 2, 11) to (start + 0, 24) = (c0 + (c1 + (c2 + c3))) - Code(Expression(5, Sub)) at (prev + 1, 12) to (start + 0, 26) @@ -27,14 +27,14 @@ Number of file 0 mappings: 9 - Code(Counter(4)) at (prev + 2, 5) to (start + 1, 2) Function name: overflow::might_overflow -Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 04, 01, 01, 12, 05, 01, 13, 02, 06, 02, 02, 06, 00, 07, 07, 01, 09, 05, 02] +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 05, 01, 01, 12, 05, 01, 13, 02, 06, 02, 02, 06, 00, 07, 07, 01, 09, 05, 02] Number of files: 1 - file 0 => global file 1 Number of expressions: 2 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) - expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) Number of file 0 mappings: 4 -- Code(Counter(0)) at (prev + 4, 1) to (start + 1, 18) +- Code(Counter(0)) at (prev + 5, 1) to (start + 1, 18) - Code(Counter(1)) at (prev + 1, 19) to (start + 2, 6) - Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7) = (c0 - c1) diff --git a/tests/coverage-map/status-quo/overflow.rs b/tests/coverage-map/overflow.rs similarity index 98% rename from tests/coverage-map/status-quo/overflow.rs rename to tests/coverage-map/overflow.rs index bbb65c1b35df6..1c40771b27478 100644 --- a/tests/coverage-map/status-quo/overflow.rs +++ b/tests/coverage-map/overflow.rs @@ -1,4 +1,5 @@ #![allow(unused_assignments)] +// compile-flags: -Coverflow-checks=yes // failure-status: 101 fn might_overflow(to_add: u32) -> u32 { diff --git a/tests/coverage-map/status-quo/panic_unwind.cov-map b/tests/coverage-map/panic_unwind.cov-map similarity index 100% rename from tests/coverage-map/status-quo/panic_unwind.cov-map rename to tests/coverage-map/panic_unwind.cov-map diff --git a/tests/coverage-map/status-quo/panic_unwind.rs b/tests/coverage-map/panic_unwind.rs similarity index 100% rename from tests/coverage-map/status-quo/panic_unwind.rs rename to tests/coverage-map/panic_unwind.rs diff --git a/tests/coverage-map/status-quo/partial_eq.cov-map b/tests/coverage-map/partial_eq.cov-map similarity index 100% rename from tests/coverage-map/status-quo/partial_eq.cov-map rename to tests/coverage-map/partial_eq.cov-map diff --git a/tests/coverage-map/status-quo/partial_eq.rs b/tests/coverage-map/partial_eq.rs similarity index 100% rename from tests/coverage-map/status-quo/partial_eq.rs rename to tests/coverage-map/partial_eq.rs diff --git a/tests/coverage-map/status-quo/simple_loop.cov-map b/tests/coverage-map/simple_loop.cov-map similarity index 100% rename from tests/coverage-map/status-quo/simple_loop.cov-map rename to tests/coverage-map/simple_loop.cov-map diff --git a/tests/coverage-map/status-quo/simple_loop.rs b/tests/coverage-map/simple_loop.rs similarity index 100% rename from tests/coverage-map/status-quo/simple_loop.rs rename to tests/coverage-map/simple_loop.rs diff --git a/tests/coverage-map/status-quo/simple_match.cov-map b/tests/coverage-map/simple_match.cov-map similarity index 100% rename from tests/coverage-map/status-quo/simple_match.cov-map rename to tests/coverage-map/simple_match.cov-map diff --git a/tests/coverage-map/status-quo/simple_match.rs b/tests/coverage-map/simple_match.rs similarity index 100% rename from tests/coverage-map/status-quo/simple_match.rs rename to tests/coverage-map/simple_match.rs diff --git a/tests/coverage-map/status-quo/sort_groups.cov-map b/tests/coverage-map/sort_groups.cov-map similarity index 70% rename from tests/coverage-map/status-quo/sort_groups.cov-map rename to tests/coverage-map/sort_groups.cov-map index db027f3dc3249..3cbda6fbe1ab8 100644 --- a/tests/coverage-map/status-quo/sort_groups.cov-map +++ b/tests/coverage-map/sort_groups.cov-map @@ -28,6 +28,21 @@ Number of file 0 mappings: 4 - Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2) = (c1 + (c0 - c1)) +Function name: sort_groups::generic_fn:: +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 11, 01, 01, 0c, 05, 01, 0d, 02, 06, 02, 02, 06, 00, 07, 07, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 17, 1) to (start + 1, 12) +- Code(Counter(1)) at (prev + 1, 13) to (start + 2, 6) +- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2) + = (c1 + (c0 - c1)) + Function name: sort_groups::generic_fn:: Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 11, 01, 01, 0c, 05, 01, 0d, 02, 06, 02, 02, 06, 00, 07, 07, 01, 01, 00, 02] Number of files: 1 @@ -44,19 +59,19 @@ Number of file 0 mappings: 4 = (c1 + (c0 - c1)) Function name: sort_groups::main -Raw bytes (28): 0x[01, 01, 02, 01, 00, 00, 02, 04, 01, 06, 01, 04, 0d, 00, 04, 0e, 02, 06, 02, 02, 06, 00, 07, 07, 01, 05, 02, 02] +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 06, 01, 04, 23, 05, 04, 24, 02, 06, 02, 02, 06, 00, 07, 07, 01, 05, 02, 02] Number of files: 1 - file 0 => global file 1 Number of expressions: 2 -- expression 0 operands: lhs = Counter(0), rhs = Zero -- expression 1 operands: lhs = Zero, rhs = Expression(0, Sub) +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) Number of file 0 mappings: 4 -- Code(Counter(0)) at (prev + 6, 1) to (start + 4, 13) -- Code(Zero) at (prev + 4, 14) to (start + 2, 6) +- Code(Counter(0)) at (prev + 6, 1) to (start + 4, 35) +- Code(Counter(1)) at (prev + 4, 36) to (start + 2, 6) - Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7) - = (c0 - Zero) + = (c0 - c1) - Code(Expression(1, Add)) at (prev + 1, 5) to (start + 2, 2) - = (Zero + (c0 - Zero)) + = (c1 + (c0 - c1)) Function name: sort_groups::other_fn Raw bytes (9): 0x[01, 01, 00, 01, 01, 17, 01, 00, 11] diff --git a/tests/coverage-map/status-quo/sort_groups.rs b/tests/coverage-map/sort_groups.rs similarity index 93% rename from tests/coverage-map/status-quo/sort_groups.rs rename to tests/coverage-map/sort_groups.rs index f89f9f3ec61fa..5adbbc6a87d1f 100644 --- a/tests/coverage-map/status-quo/sort_groups.rs +++ b/tests/coverage-map/sort_groups.rs @@ -7,7 +7,7 @@ fn main() { let cond = std::env::args().len() > 1; generic_fn::<()>(cond); generic_fn::<&'static str>(!cond); - if false { + if std::hint::black_box(false) { generic_fn::(cond); } generic_fn::(cond); diff --git a/tests/coverage-map/status-quo/if.cov-map b/tests/coverage-map/status-quo/if.cov-map deleted file mode 100644 index 391a69e0e821d..0000000000000 --- a/tests/coverage-map/status-quo/if.cov-map +++ /dev/null @@ -1,15 +0,0 @@ -Function name: if::main -Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 03, 01, 12, 10, 05, 13, 05, 05, 06, 02, 05, 06, 00, 07, 07, 01, 01, 00, 02] -Number of files: 1 -- file 0 => global file 1 -Number of expressions: 2 -- expression 0 operands: lhs = Counter(0), rhs = Counter(1) -- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) -Number of file 0 mappings: 4 -- Code(Counter(0)) at (prev + 3, 1) to (start + 18, 16) -- Code(Counter(1)) at (prev + 19, 5) to (start + 5, 6) -- Code(Expression(0, Sub)) at (prev + 5, 6) to (start + 0, 7) - = (c0 - c1) -- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2) - = (c1 + (c0 - c1)) - diff --git a/tests/coverage-map/status-quo/if.rs b/tests/coverage-map/status-quo/if.rs deleted file mode 100644 index 8ad5042ff7baf..0000000000000 --- a/tests/coverage-map/status-quo/if.rs +++ /dev/null @@ -1,28 +0,0 @@ -#![allow(unused_assignments, unused_variables)] - -fn main() { - // Initialize test constants in a way that cannot be determined at compile time, to ensure - // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from - // dependent conditions. - let - is_true - = - std::env::args().len() - == - 1 - ; - let - mut - countdown - = - 0 - ; - if - is_true - { - countdown - = - 10 - ; - } -} diff --git a/tests/coverage-map/status-quo/test_harness.cov-map b/tests/coverage-map/test_harness.cov-map similarity index 100% rename from tests/coverage-map/status-quo/test_harness.cov-map rename to tests/coverage-map/test_harness.cov-map diff --git a/tests/coverage-map/status-quo/test_harness.rs b/tests/coverage-map/test_harness.rs similarity index 100% rename from tests/coverage-map/status-quo/test_harness.rs rename to tests/coverage-map/test_harness.rs diff --git a/tests/coverage-map/status-quo/tight_inf_loop.cov-map b/tests/coverage-map/tight_inf_loop.cov-map similarity index 100% rename from tests/coverage-map/status-quo/tight_inf_loop.cov-map rename to tests/coverage-map/tight_inf_loop.cov-map diff --git a/tests/coverage-map/status-quo/tight_inf_loop.rs b/tests/coverage-map/tight_inf_loop.rs similarity index 100% rename from tests/coverage-map/status-quo/tight_inf_loop.rs rename to tests/coverage-map/tight_inf_loop.rs diff --git a/tests/coverage-map/status-quo/try_error_result.cov-map b/tests/coverage-map/try_error_result.cov-map similarity index 100% rename from tests/coverage-map/status-quo/try_error_result.cov-map rename to tests/coverage-map/try_error_result.cov-map diff --git a/tests/coverage-map/status-quo/try_error_result.rs b/tests/coverage-map/try_error_result.rs similarity index 100% rename from tests/coverage-map/status-quo/try_error_result.rs rename to tests/coverage-map/try_error_result.rs diff --git a/tests/coverage-map/status-quo/unused.cov-map b/tests/coverage-map/unused.cov-map similarity index 100% rename from tests/coverage-map/status-quo/unused.cov-map rename to tests/coverage-map/unused.cov-map diff --git a/tests/coverage-map/status-quo/unused.rs b/tests/coverage-map/unused.rs similarity index 100% rename from tests/coverage-map/status-quo/unused.rs rename to tests/coverage-map/unused.rs diff --git a/tests/coverage-map/unused_mod.cov-map b/tests/coverage-map/unused_mod.cov-map new file mode 100644 index 0000000000000..241cb2610ffc0 --- /dev/null +++ b/tests/coverage-map/unused_mod.cov-map @@ -0,0 +1,16 @@ +Function name: unused_mod::main +Raw bytes (9): 0x[01, 02, 00, 01, 01, 04, 01, 02, 02] +Number of files: 1 +- file 0 => global file 2 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 4, 1) to (start + 2, 2) + +Function name: unused_mod::unused_module::never_called_function (unused) +Raw bytes (9): 0x[01, 01, 00, 01, 00, 02, 01, 02, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Zero) at (prev + 2, 1) to (start + 2, 2) + diff --git a/tests/coverage-map/unused_mod.rs b/tests/coverage-map/unused_mod.rs new file mode 100644 index 0000000000000..6e62839c99856 --- /dev/null +++ b/tests/coverage-map/unused_mod.rs @@ -0,0 +1,6 @@ +#[path = "auxiliary/unused_mod_helper.rs"] +mod unused_module; + +fn main() { + println!("hello world!"); +} diff --git a/tests/coverage-map/uses_crate.cov-map b/tests/coverage-map/uses_crate.cov-map new file mode 100644 index 0000000000000..9c06eab700507 --- /dev/null +++ b/tests/coverage-map/uses_crate.cov-map @@ -0,0 +1,40 @@ +Function name: used_crate::used_from_bin_crate_and_lib_crate_generic_function::> +Raw bytes (9): 0x[01, 01, 00, 01, 01, 1b, 01, 02, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 27, 1) to (start + 2, 2) + +Function name: used_crate::used_only_from_bin_crate_generic_function::<&alloc::vec::Vec> +Raw bytes (9): 0x[01, 01, 00, 01, 01, 13, 01, 02, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 19, 1) to (start + 2, 2) + +Function name: used_crate::used_only_from_bin_crate_generic_function::<&str> +Raw bytes (9): 0x[01, 01, 00, 01, 01, 13, 01, 02, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 19, 1) to (start + 2, 2) + +Function name: used_crate::used_with_same_type_from_bin_crate_and_lib_crate_generic_function::<&str> +Raw bytes (9): 0x[01, 01, 00, 01, 01, 1f, 01, 02, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 31, 1) to (start + 2, 2) + +Function name: uses_crate::main +Raw bytes (9): 0x[01, 02, 00, 01, 01, 0c, 01, 07, 02] +Number of files: 1 +- file 0 => global file 2 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 12, 1) to (start + 7, 2) + diff --git a/tests/coverage-map/uses_crate.rs b/tests/coverage-map/uses_crate.rs new file mode 100644 index 0000000000000..ab203ad781d66 --- /dev/null +++ b/tests/coverage-map/uses_crate.rs @@ -0,0 +1,19 @@ +// This test was failing on Linux for a while due to #110393 somehow making +// the unused functions not instrumented, but it seems to be fine now. + +// Validates coverage now works with optimizations +// compile-flags: -C opt-level=3 + +#![allow(unused_assignments, unused_variables)] + +// aux-build:used_crate.rs +extern crate used_crate; + +fn main() { + used_crate::used_function(); + let some_vec = vec![1, 2, 3, 4]; + used_crate::used_only_from_bin_crate_generic_function(&some_vec); + used_crate::used_only_from_bin_crate_generic_function("used from bin uses_crate.rs"); + used_crate::used_from_bin_crate_and_lib_crate_generic_function(some_vec); + used_crate::used_with_same_type_from_bin_crate_and_lib_crate_generic_function("interesting?"); +} diff --git a/tests/coverage-map/uses_inline_crate.cov-map b/tests/coverage-map/uses_inline_crate.cov-map new file mode 100644 index 0000000000000..6b621825c8861 --- /dev/null +++ b/tests/coverage-map/uses_inline_crate.cov-map @@ -0,0 +1,55 @@ +Function name: used_inline_crate::used_from_bin_crate_and_lib_crate_generic_function::> +Raw bytes (9): 0x[01, 01, 00, 01, 01, 2c, 01, 02, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 44, 1) to (start + 2, 2) + +Function name: used_inline_crate::used_inline_function +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 14, 01, 06, 0f, 05, 06, 10, 02, 06, 02, 02, 06, 00, 07, 07, 01, 05, 01, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 20, 1) to (start + 6, 15) +- Code(Counter(1)) at (prev + 6, 16) to (start + 2, 6) +- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 5) to (start + 1, 2) + = (c1 + (c0 - c1)) + +Function name: used_inline_crate::used_only_from_bin_crate_generic_function::<&alloc::vec::Vec> +Raw bytes (9): 0x[01, 01, 00, 01, 01, 21, 01, 02, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 33, 1) to (start + 2, 2) + +Function name: used_inline_crate::used_only_from_bin_crate_generic_function::<&str> +Raw bytes (9): 0x[01, 01, 00, 01, 01, 21, 01, 02, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 33, 1) to (start + 2, 2) + +Function name: used_inline_crate::used_with_same_type_from_bin_crate_and_lib_crate_generic_function::<&str> +Raw bytes (9): 0x[01, 01, 00, 01, 01, 31, 01, 02, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 49, 1) to (start + 2, 2) + +Function name: uses_inline_crate::main +Raw bytes (9): 0x[01, 02, 00, 01, 01, 0c, 01, 0a, 02] +Number of files: 1 +- file 0 => global file 2 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 12, 1) to (start + 10, 2) + diff --git a/tests/coverage-map/uses_inline_crate.rs b/tests/coverage-map/uses_inline_crate.rs new file mode 100644 index 0000000000000..d7b4c3c057f46 --- /dev/null +++ b/tests/coverage-map/uses_inline_crate.rs @@ -0,0 +1,22 @@ +// This test was failing on Linux for a while due to #110393 somehow making +// the unused functions not instrumented, but it seems to be fine now. + +// Validates coverage now works with optimizations +// compile-flags: -C opt-level=3 + +#![allow(unused_assignments, unused_variables)] + +// aux-build:used_inline_crate.rs +extern crate used_inline_crate; + +fn main() { + used_inline_crate::used_function(); + used_inline_crate::used_inline_function(); + let some_vec = vec![1, 2, 3, 4]; + used_inline_crate::used_only_from_bin_crate_generic_function(&some_vec); + used_inline_crate::used_only_from_bin_crate_generic_function("used from bin uses_crate.rs"); + used_inline_crate::used_from_bin_crate_and_lib_crate_generic_function(some_vec); + used_inline_crate::used_with_same_type_from_bin_crate_and_lib_crate_generic_function( + "interesting?", + ); +} diff --git a/tests/coverage-map/status-quo/while.cov-map b/tests/coverage-map/while.cov-map similarity index 100% rename from tests/coverage-map/status-quo/while.cov-map rename to tests/coverage-map/while.cov-map diff --git a/tests/coverage-map/status-quo/while.rs b/tests/coverage-map/while.rs similarity index 100% rename from tests/coverage-map/status-quo/while.rs rename to tests/coverage-map/while.rs diff --git a/tests/coverage-map/status-quo/while_early_ret.cov-map b/tests/coverage-map/while_early_ret.cov-map similarity index 100% rename from tests/coverage-map/status-quo/while_early_ret.cov-map rename to tests/coverage-map/while_early_ret.cov-map diff --git a/tests/coverage-map/status-quo/while_early_ret.rs b/tests/coverage-map/while_early_ret.rs similarity index 100% rename from tests/coverage-map/status-quo/while_early_ret.rs rename to tests/coverage-map/while_early_ret.rs diff --git a/tests/coverage-map/status-quo/yield.cov-map b/tests/coverage-map/yield.cov-map similarity index 100% rename from tests/coverage-map/status-quo/yield.cov-map rename to tests/coverage-map/yield.cov-map diff --git a/tests/coverage-map/status-quo/yield.rs b/tests/coverage-map/yield.rs similarity index 100% rename from tests/coverage-map/status-quo/yield.rs rename to tests/coverage-map/yield.rs diff --git a/tests/run-coverage/long_and_wide.coverage b/tests/run-coverage/long_and_wide.coverage new file mode 100644 index 0000000000000..d7d29ca40cddd --- /dev/null +++ b/tests/run-coverage/long_and_wide.coverage @@ -0,0 +1,151 @@ + LL| |// compile-flags: --edition=2021 + LL| |// ignore-tidy-linelength + LL| | + LL| |// This file deliberately contains line and column numbers larger than 127, + LL| |// to verify that `coverage-dump`'s ULEB128 parser can handle them. + LL| | + LL| 1|fn main() { + LL| 1| wide_function(); + LL| 1| long_function(); + LL| 1| far_function(); + LL| 1|} + LL| | + LL| |#[rustfmt::skip] + LL| 1|fn wide_function() { /* */ (); } + LL| | + LL| 1|fn long_function() { + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1| // + LL| 1|} + LL| | + LL| 1|fn far_function() {} + diff --git a/tests/run-coverage/long_and_wide.rs b/tests/run-coverage/long_and_wide.rs new file mode 100644 index 0000000000000..a7cbcd4802791 --- /dev/null +++ b/tests/run-coverage/long_and_wide.rs @@ -0,0 +1,150 @@ +// compile-flags: --edition=2021 +// ignore-tidy-linelength + +// This file deliberately contains line and column numbers larger than 127, +// to verify that `coverage-dump`'s ULEB128 parser can handle them. + +fn main() { + wide_function(); + long_function(); + far_function(); +} + +#[rustfmt::skip] +fn wide_function() { /* */ (); } + +fn long_function() { + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // +} + +fn far_function() {} diff --git a/tests/run-coverage/overflow.coverage b/tests/run-coverage/overflow.coverage index cee076e88cd43..4f8dffc0c4814 100644 --- a/tests/run-coverage/overflow.coverage +++ b/tests/run-coverage/overflow.coverage @@ -1,4 +1,5 @@ LL| |#![allow(unused_assignments)] + LL| |// compile-flags: -Coverflow-checks=yes LL| |// failure-status: 101 LL| | LL| 4|fn might_overflow(to_add: u32) -> u32 { diff --git a/tests/run-coverage/overflow.rs b/tests/run-coverage/overflow.rs index bbb65c1b35df6..1c40771b27478 100644 --- a/tests/run-coverage/overflow.rs +++ b/tests/run-coverage/overflow.rs @@ -1,4 +1,5 @@ #![allow(unused_assignments)] +// compile-flags: -Coverflow-checks=yes // failure-status: 101 fn might_overflow(to_add: u32) -> u32 { diff --git a/tests/run-coverage/sort_groups.coverage b/tests/run-coverage/sort_groups.coverage index 8733bf48a9c8d..c70d7b3b28253 100644 --- a/tests/run-coverage/sort_groups.coverage +++ b/tests/run-coverage/sort_groups.coverage @@ -7,7 +7,7 @@ LL| 1| let cond = std::env::args().len() > 1; LL| 1| generic_fn::<()>(cond); LL| 1| generic_fn::<&'static str>(!cond); - LL| 1| if false { + LL| 1| if std::hint::black_box(false) { LL| 0| generic_fn::(cond); LL| 1| } LL| 1| generic_fn::(cond); diff --git a/tests/run-coverage/sort_groups.rs b/tests/run-coverage/sort_groups.rs index f89f9f3ec61fa..5adbbc6a87d1f 100644 --- a/tests/run-coverage/sort_groups.rs +++ b/tests/run-coverage/sort_groups.rs @@ -7,7 +7,7 @@ fn main() { let cond = std::env::args().len() > 1; generic_fn::<()>(cond); generic_fn::<&'static str>(!cond); - if false { + if std::hint::black_box(false) { generic_fn::(cond); } generic_fn::(cond); diff --git a/tests/run-coverage/trivial.coverage b/tests/run-coverage/trivial.coverage new file mode 100644 index 0000000000000..4f417979ef97d --- /dev/null +++ b/tests/run-coverage/trivial.coverage @@ -0,0 +1,4 @@ + LL| |// compile-flags: --edition=2021 + LL| | + LL| 1|fn main() {} + diff --git a/tests/run-coverage/trivial.rs b/tests/run-coverage/trivial.rs new file mode 100644 index 0000000000000..d0a9b44fb3605 --- /dev/null +++ b/tests/run-coverage/trivial.rs @@ -0,0 +1,3 @@ +// compile-flags: --edition=2021 + +fn main() {}