Skip to content

[MC/DC] Nested decision #125403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 31 commits into
base: main
Choose a base branch
from
Draft

[MC/DC] Nested decision #125403

wants to merge 31 commits into from

Conversation

To resolve the error, rename mcdc-error-nests.cpp -> mcdc-nested-expr.cpp at first.

- `func_condop`
  A corner case that contains close decisions.
- `func_expect`
  Uses `__builtin_expect`. (#124565)
- `func_lnot`
  Contains logical not(s) `!` among MC/DC binary operators. (#124563)

mcdc-single-cond.cpp is for #95336.
CoverageMappingWriter reorders `Region`s by `endLoc DESC` to
prioritize wider `Decision` with the same `startLoc`.

In `llvm-cov`, tweak seeking Decisions by reversal order to find
smaller Decision first.
Introduce `ID` and `InvalidID`. Then `DecisionByStmt` can have three
states.

* Not assigned if the Stmt(Expr) doesn't exist.
* When `DecisionByStmt[Expr]` exists:
  * Invalid and should be ignored if `ID == Invalid`.
  * Valid if `ID != Invalid`. Other member will be filled in the
    Mapper.
- Get rid of the old `DecisionStack` and dissolve it into push/pop
  `CurCondIDs` in `VisitBin`, since `VisitBin` is recursive.

- Introduce the new `DecisionStack` with `DecisionState` to handle the
  current `Decision` in nested `Decision`s.
  - The stack has the sentinel that has `DecisionExpr = nullptr`.
  - Split out `checkDecisionRootOrPush` from `pushAndAssignIDs` for
    non-BinOp. It assigns `CondID` to `E` (instead of assignment LHS
    in `pushAndAssignIDs`).
  - The stack is manupilated at the top Decision operator in `VisitBin`.
    - The stack grows at the entrance of the Decision with the initial
      state.
    - In the same level in `VisitBin`, the stack is popped and the
      `Decision` record is emitted.
- Introduce `DecisionEndToSince` to sweep `MCDCBranch`es partially in
  `cancelDecision`.
`MCDCLogOpStack` is used only for detection of the Decision root. It
can be detected with `MCDC::State::DecisionByStmt`.
MCDCCondBitmapAddr is moved from `CodeGenFunction` into `MCDCState`
and created for each Decision.

In `maybeCreateMCDCCondBitmap`, Allocate bitmaps for all valid
Decisions and emit them order by ID, to prevent nondeterminism.
…est/covmapdesc', 'users/chapuni/mcdc/nest/covgen' and 'users/chapuni/mcdc/nest/logopstack' into users/chapuni/mcdc/nest/nest-base
A warning "contains an operation with a nested boolean expression." is
no longer emitter. At the moment, split expressions are treated as
individual Decisions.
In the current implementation, `!(a || b) && c` was not treated as one
Decision with three terms.

Fixes #124563
…/nest/expect' into users/chapuni/mcdc/nest/trunk

Conflicts:
	clang/include/clang/AST/IgnoreExpr.h
	clang/lib/CodeGen/CodeGenFunction.cpp
…onditions

`-fmcdc-single-conditions` is `CC1Option` for now.

This change discovers `isInstrumentedCondition(Cond)` on
`DoStmt/ForStmt/IfStmt/WhleStmt/AbstractConditionalOperator` and add
them into Decisions.

An example of the report:

```
MC/DC Decision Region (mmm:nn) to (mmm:nn)

  Number of Conditions: 1
     Condition C1 -->(mmm:nn)

  Executed MC/DC Test Vectors:

     C1    Result
  1 { F  = F      }
  2 { T  = T      }

  C1-Pair: covered: (1,2)
  MC/DC Coverage for Expression: 100.00%
```

The Decision is covered only if both `true` and `false` are covered.

Fixes #95336
…dc/nest/lnot' into users/chapuni/mcdc/nest/trunk

Conflicts:
	clang/docs/ReleaseNotes.rst
@ornata ornata self-requested a review February 7, 2025 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant