Commit Graph

117 Commits

Author SHA1 Message Date
Zalathar
afe190204b coverage: Regression test for inlining into an uninstrumented crate 2024-11-02 23:20:14 +11:00
Michael Goulet
cdbf28af76 Dont ICE when computing coverage of synthetic async closure body 2024-10-18 20:14:02 +11:00
Zalathar
599f95ecc2 coverage: Include the highest counter ID seen in .cov-map dumps
When making changes that have a large impact on coverage counter creation, this
makes it easier to see whether the number of physical counters has changed.

(The highest counter ID seen in coverage maps is not necessarily the same as
the number of physical counters actually used by the instrumented code, but
it's the best approximation we can get from looking only at the coverage maps,
and it should be reasonably accurate in most cases.)
2024-10-11 21:04:37 +11:00
Zalathar
96224d80ce compiletest: Remove the magic hacks for finding output with lto=thin
This hack was intended to handle the case where `-Clto=thin` causes the
compiler to emit multiple output files (when producing LLVM-IR or assembly).

The hack only affects 4 tests, of which 3 are just meta-tests for the hack
itself. The one remaining test that motivated the hack currently doesn't even
need it!

(`tests/codegen/issues/issue-81408-dllimport-thinlto-windows.rs`)
2024-10-11 11:28:42 +11:00
Zalathar
27583378d3 Simplify the directives for ignoring coverage-test modes 2024-10-08 22:51:53 +11:00
zhuyunxing
6e3e19f714 coverage. Adapt to mcdc mapping formats introduced by llvm 19 2024-10-08 11:15:24 +08:00
zhuyunxing
911ac56e95 coverage. Disable supporting mcdc on llvm-18 2024-10-08 10:50:18 +08:00
Ralf Jung
7d63efdb8c fix GVN trying to transmute pointers to integers 2024-10-05 17:55:23 +02:00
Josh Stone
6fd8a50680 Update the minimum external LLVM to 18 2024-09-18 13:53:31 -07:00
Zalathar
e96b4e479a coverage: Extract executor::block_on from several async coverage tests
By moving `block_on` to an auxiliary crate, we avoid having to keep a separate
copy of it in every async test.

(This also incorporates some small tweaks to the headers in `await_ready.rs`.)
2024-09-10 16:08:36 +10:00
Jonathan Conder
25d183057e coverage: Treat await similar to a macro
Currently `await` is only counted towards coverage if the containing
function is suspended and resumed at least once. This is because it
expands to code which contains a branch on the discriminant of `Poll`.

By treating it like a branching macro (e.g. `assert!`), these
implementation details will be hidden from the coverage results.
2024-09-06 17:01:59 +12:00
Jonathan Conder
3446ca535e coverage: Add test to codify existing behavior
Currently `await` is only counted towards coverage if the containing
function is suspended and resumed at least once. A future commit will
fix this and update the test to reflect the new behavior.
2024-09-06 16:50:23 +12:00
Zalathar
68df46c4c2 Finish blessing coverage/mcdc tests after LLVM 19 upgrade 2024-08-01 13:36:50 +10:00
Josh Stone
33a36ea438 Bless coverage/mcdc for line number changes 2024-07-30 18:25:05 -07:00
Krasimir Georgiev
00bfd702dc Disable MC/DC tests on LLVM 19
Disable the tests and generate an error if MC/DC is used on LLVM 19.
The support will be ported separately, as it is substantially
different on LLVM 19, and there are no plans to support both
versions.
2024-07-30 10:22:48 +02:00
Camille GILLOT
6e3cff7094 Bless coverage. 2024-07-13 12:02:12 +00:00
Camille GILLOT
76f5bc6a9f Create mapped places upon seeing them in the body. 2024-07-13 11:54:25 +00:00
zhuyunxing
83fa6b726a coverage. Fix panic when generating mcdc code for inlined functions 2024-07-09 14:28:40 +08:00
zhuyunxing
c77788f011 coverage. MCDC tests also report branches coverage 2024-07-09 14:28:40 +08:00
zhuyunxing
4f6140258f coverage. Group mcdc tests in one directory 2024-07-09 14:28:40 +08:00
Zalathar
63c04f05e6 coverage: Extract hole spans from HIR instead of MIR
This makes it possible to treat more kinds of nested item/code as holes,
instead of being restricted to closures.
2024-07-08 21:22:56 +10:00
Zalathar
9b2c58d1fa coverage: Test for handling of nested item spans 2024-07-08 20:24:15 +10:00
Matthias Krüger
c4d0c08925
Rollup merge of #126956 - joboet:fmt_no_extern_ty, r=RalfJung
core: avoid `extern type`s in formatting infrastructure

```@RalfJung``` [said](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Use.20of.20.60extern.20type.60.20in.20formatting.20machinery/near/446552837):

>How attached are y'all to using `extern type` in the formatting machinery?
Seems like this was introduced a [long time ago](34ef8f5441). However, it's also [not really compatible with Stacked Borrows](https://github.com/rust-lang/unsafe-code-guidelines/issues/256), and only works currently because we effectively treat references-to-extern-type almost like raw pointers in Stacked Borrows -- which of course is unsound, it's not how LLVM works. I was planning to make Miri emit a warning when this happens to avoid cases like [this](https://github.com/rust-lang/rust/issues/126814#issuecomment-2183816373) where people use extern type specifically to silence Miri without realizing what happens. but with the formatting machinery using  extern type, this warning would just show up everywhere...
>
> The "proper" way to do this in Stacked Borrows is to use raw pointers (or `NonNull`).

This PR does just that.

r? ```@RalfJung```
2024-06-28 08:34:08 +02:00
Jacob Pratt
70b69a2384
Rollup merge of #126721 - Zalathar:nested-cov-attr, r=oli-obk
coverage: Make `#[coverage(..)]` apply recursively to nested functions

This PR makes the (currently-unstable) `#[coverage(off)]` and `#[coverage(on)]` attributes apply recursively to all nested functions/closures, instead of just the function they are directly attached to.

Those attributes can now also be applied to modules and to impl/impl-trait blocks, where they have no direct effect, but will be inherited by all enclosed functions/closures/methods that don't override the inherited value.

---

Fixes #126625.
2024-06-27 02:06:18 -04:00
Zalathar
7f37f8af5f coverage: Allow #[coverage(..)] on impl and mod
These attributes apply to all enclosed functions/methods/closures, unless
explicitly overridden by another coverage attribute.
2024-06-26 10:08:05 +10:00
Zalathar
3262611cc5 coverage: Apply #[coverage(..)] recursively to nested functions 2024-06-26 10:08:05 +10:00
joboet
7526416ba6
update coverage test 2024-06-26 00:06:27 +02:00
Scott McMurray
49d353bb9f Update coverage maps in tests 2024-06-22 21:37:26 -07:00
Scott McMurray
4341cb709d I'd never even heard of a coverage map 2024-06-20 22:16:59 -07:00
bors
1aaab8b9f8 Auto merge of #116088 - nbdd0121:unwind, r=Amanieu,RalfJung
Stabilise `c_unwind`

Fix #74990
Fix #115285 (that's also where FCP is happening)

Marking as draft PR for now due to `compiler_builtins` issues

r? `@Amanieu`
2024-06-20 11:22:59 +00:00
Gary Guo
5812b1fd12 Remove c_unwind from tests and fix tests 2024-06-19 13:54:55 +01:00
León Orell Valerian Liehr
a7cf6ece62
Rollup merge of #125766 - RenjiSann:fresh-mcdc-branch-on-bool, r=nnethercote
MCDC Coverage: instrument last boolean RHS operands from condition coverage

Fresh PR from #124652

--

This PR ensures that the top-level boolean expressions that are not part of the control flow are correctly instrumented thanks to condition coverage.

See discussion on https://github.com/rust-lang/rust/issues/124120.
Depends on `@Zalathar` 's condition coverage implementation #125756.
2024-06-19 13:04:57 +02:00
Dorian Péron
e15adef457 tests(coverage): Bless mcdc_non_control_flow tests 2024-06-19 07:41:51 +00:00
Guillaume Gomez
9f455d3246
Rollup merge of #126621 - Zalathar:test-coverage-attr, r=petrochenkov
More thorough status-quo tests for `#[coverage(..)]`

In light of the stabilization push at https://github.com/rust-lang/rust/issues/84605#issuecomment-2166514660, I have written some tests to more thoroughly capture the current behaviour of the `#[coverage(..)]` attribute.

These tests aim to capture the *current* behaviour, which is not necessarily the desired behaviour. For example, some of the error message are not great, some things that perhaps ought to cause an error do not, and recursive coverage attributes have not been implemented yet.

`@rustbot` label +A-code-coverage
2024-06-18 15:30:47 +02:00
Zalathar
5093658632 Add more thorough coverage tests for #[coverage(..)] in nested functions
These tests reflect the current implementation behaviour, which is not
necessarily the desired behaviour.
2024-06-18 21:27:34 +10:00
Zalathar
abc2c702af coverage: Add debugging flag -Zcoverage-options=no-mir-spans
When set, this flag skips the code that normally extracts coverage spans from
MIR statements and terminators. That sometimes makes it easier to debug branch
coverage and MC/DC coverage, because the coverage output is less noisy.

For internal debugging only. If other code changes would make it hard to keep
supporting this flag, remove it.
2024-06-17 21:16:15 +10:00
Zalathar
2fa78f3a2a coverage: Replace the old span refiner with a single function
As more and more of the span refiner's functionality has been pulled out into
separate early passes, it has finally reached the point where we can remove the
rest of the old `SpansRefiner` code, and replace it with a single
modestly-sized function.
2024-06-12 22:59:24 +10:00
Zalathar
0bfdb8d33d coverage: Add tests/coverage/loop-break.rs
This is a modified copy of `tests/mir-opt/coverage/instrument_coverage.rs`.
2024-06-12 22:48:11 +10:00
Zalathar
dc6def3042 coverage: Add tests/coverage/assert-ne.rs
This test extracts a fragment of `issue-84561.rs` that has historically proven
troublesome when trying to modify how spans are extracted from MIR.
2024-06-12 22:38:16 +10:00
Dorian Péron
acd6e4c0fd tests(coverage): Add mcdc_non_control_flow tests 2024-06-05 08:04:05 +00:00
Zalathar
6d1557f268 coverage: Use hole spans to carve up coverage spans into separate buckets
This performs the same task as the hole-carving code in the main span refiner,
but in a separate earlier pass.
2024-06-04 13:51:08 +10:00
Zalathar
35a8746832 coverage: Instrument the RHS value of lazy logical operators
When a lazy logical operator (`&&` or `||`) occurs outside of an `if`
condition, it normally doesn't have any associated control-flow branch, so we
don't have an existing way to track whether it was true or false.

This patch adds special code to handle this case, by inserting extra MIR blocks
in a diamond shape after evaluating the RHS. This gives us a place to insert
the appropriate marker statements, which can then be given their own counters.
2024-05-30 15:38:46 +10:00
Dorian Péron
20174e6638 coverage: Add a test for -Zcoverage-options=condition 2024-05-30 15:38:46 +10:00
Matthias Krüger
9a61146765
Rollup merge of #125700 - Zalathar:limit-overflow, r=nnethercote
coverage: Avoid overflow when the MC/DC condition limit is exceeded

Fix for the test failure seen in https://github.com/rust-lang/rust/pull/124571#issuecomment-2099620869.

If we perform this subtraction first, it can sometimes overflow to -1 before the addition can bring its value back to 0.

That behaviour seems to be benign, but it nevertheless causes test failures in compiler configurations that check for overflow.

``@rustbot`` label +A-code-coverage
2024-05-29 20:12:33 +02:00
Zalathar
34a1828fea coverage: Add tests for the MC/DC condition limit 2024-05-29 20:12:20 +10:00
Zalathar
9dc6e08279 Manually run x fmt on all source files in tests/coverage/
Currently we can't automatically enforce formatting on tests (see #125637), but
we can at least keep things relatively tidy by occasionally running the
formatter manually.

This was done by temporarily commenting out the `"/tests/"` exclusion in
`rustfmt.toml`, and then running `x fmt tests/coverage` and
`x test coverage --bless`.
2024-05-29 14:34:17 +10:00
Zalathar
448d63e946 Tweak various coverage test files for slightly nicer formatting
For coverage tests, splitting code across multiple lines often makes the
resulting coverage report easier to interpret, so we force rustfmt to retain
line breaks by adding dummy line comments with `//`.
2024-05-29 14:34:11 +10:00
Zalathar
d01df6f9aa coverage: Simplify counter expressions using simple algebra
Some of these cases currently don't occur in practice, but are included for
completeness, and to avoid having to add them later as branch coverage and
MC/DC coverage start building more complex expressions.
2024-05-14 13:58:40 +10:00
bors
5486f0c1c2 Auto merge of #124223 - Zalathar:conditional-let, r=compiler-errors
coverage: Branch coverage support for let-else and if-let

This PR adds branch coverage instrumentation for let-else and if-let, including let-chains.

This lifts two of the limitations listed at #124118.
2024-05-07 22:28:51 +00:00
bors
d2d24e395a Auto merge of #123602 - cjgillot:gvn-borrowed, r=oli-obk
Account for immutably borrowed locals in MIR copy-prop and GVN

For the most part, we consider that immutably borrowed `Freeze` locals still fulfill SSA conditions. As the borrow is immutable, any use of the local will have the value given by the single assignment, and there can be no surprise.

This allows copy-prop to merge a non-borrowed local with a borrowed local. We chose to keep copy-classes heads unborrowed, as those may be easier to optimize in later passes.

This also allows to GVN the value behind an immutable borrow. If a SSA local is borrowed, dereferencing that borrow is equivalent to copying the local's value: re-executing the assignment between the borrow and the dereference would be UB.

r? `@ghost` for perf
2024-05-03 21:50:13 +00:00