Commit Graph

105 Commits

Author SHA1 Message Date
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
Zalathar
7c87ad0430 coverage: Add branch coverage support for if-let and let-chains 2024-04-30 22:35:55 +10:00
Zalathar
c9dd07dd5e coverage: Add branch coverage support for let-else 2024-04-30 22:35:54 +10:00
bors
7a58674259 Auto merge of #124255 - RenjiSann:renji/mcdc-nested-expressions, r=Zalathar
MCDC coverage: support nested decision coverage

#123409 provided the initial MCDC coverage implementation.

As referenced in #124144, it does not currently support "nested" decisions, like the following example :

```rust
fn nested_if_in_condition(a: bool, b: bool, c: bool) {
    if a && if b || c { true } else { false } {
        say("yes");
    } else {
        say("no");
    }
}
```

Note that there is an if-expression (`if b || c ...`) embedded inside a boolean expression in the decision of an outer if-expression.

This PR proposes a workaround for this cases, by introducing a Decision context stack, and by handing several `temporary condition bitmaps` instead of just one.
When instrumenting boolean expressions, if the current node is a leaf condition (i.e. not a `||`/`&&` logical operator nor a `!` not operator), we insert a new decision context, such that if there are more boolean expressions inside the condition, they are handled as separate expressions.

On the codegen LLVM side, we allocate as many `temp_cond_bitmap`s as necessary to handle the maximum encountered decision depth.
2024-04-29 11:54:49 +00:00
Dorian Péron
eb422d5c7e tests(mcdc-coverage): Add tests for nested decision structures in mcdc_nested_if.rs 2024-04-29 09:13:41 +00:00
Oli Scherer
aef0f4024a Error on using yield without also using #[coroutine] on the closure
And suggest adding the `#[coroutine]` to the closure
2024-04-24 08:05:29 +00:00
Zalathar
3de87feba2 coverage: Branch coverage tests for match arms 2024-04-22 21:55:33 +10:00
Zalathar
7f432dfb23 coverage: Branch coverage test for if-let and let-chains 2024-04-22 21:55:33 +10:00
Zalathar
4f7a47798e coverage: Branch coverage test for let-else 2024-04-22 21:55:33 +10:00
许杰友 Jieyou Xu (Joe)
f13cd0c8d0
Rollup merge of #124053 - Zalathar:lazy-boolean, r=Mark-Simulacrum
coverage: Branch coverage tests for lazy boolean operators

The current branch coverage implementation already supports the `&&` and `||` operators (even outside of an `if` condition), as a natural consequence of how they are desugared/lowered, but we didn't have any specific tests for them. This PR adds some appropriate tests.

I've also moved the existing branch coverage tests into a `coverage/branch` subdirectory, so that they don't become unwieldy as I add more branch coverage tests.

``@rustbot`` label +A-code-coverage
2024-04-20 21:45:36 +01:00
Camille GILLOT
9b846d4637 Dereference immutable borrows in GVN. 2024-04-20 19:22:13 +00:00
zhuyunxing
402dc38d99 coverage. Add basic tests for MC/DC 2024-04-20 00:34:40 +08:00
Zalathar
25b9f84413 coverage: Branch coverage tests for lazy boolean operators 2024-04-17 12:32:30 +10:00