Skip to content

[llvm-cov][MC/DC][Qualification] Wrong computation of conditions #110090

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

Open
escherle-validas opened this issue Sep 26, 2024 · 2 comments
Open
Labels

Comments

@escherle-validas
Copy link

Wrong computation of conditions

Criticality: MEDIUM

In the attached example there are 10 conditions, however the tool
a) splits up the entire decision in 2 separate decisions with 3 conditions each (for C++) and
b) computes only 3 conditions (for Rust).
Also the specified "positions" are wrong, i.e. do not point to the right places.
Furthermore it is critical, that Rust and C++ differ.

Rust:
columns_of_conditions_rust

Source code and generated reports:
Test_000010.zip

C++
columns_of_conditions_cpp

Source code and generated reports:
Test_000010.zip

@escherle-validas
Copy link
Author

Since we have no reply from you yet, I would like to ask for a status update for this issue. Are there any plans how this will be handled?

@Lambdaris
Copy link

Lambdaris commented Oct 23, 2024

Not sure which version of rust you used. I check it on the latest nightly rustc and it shows

    2|      1|    if ((false && true) && (false == (v2 == false))) == ((v0 == v2) || (v0 || v0 == v2)) {
  ------------------
  |---> MC/DC Decision Region (2:8) to (2:53)
  |
  |  Number of Conditions: 3
  |     Condition C1 --> (2:10)
  |     Condition C2 --> (2:19)
  |     Condition C3 --> (2:28)
  |
  |  Executed MC/DC Test Vectors:
  |
  |     C1, C2, C3    Result
  |  1 { F,  C,  C  = F      }
  |
  |  C1-Pair: not covered
  |  C2-Pair: constant folded
  |  C3-Pair: constant folded
  |  MC/DC Coverage for Decision: 0.00%
  |
  |---> MC/DC Decision Region (2:57) to (2:89)
  |
  |  Number of Conditions: 3
  |     Condition C1 --> (2:58)
  |     Condition C2 --> (2:73)
  |     Condition C3 --> (2:79)
  |
  |  Executed MC/DC Test Vectors:
  |
  |     C1, C2, C3    Result
  |  1 { F,  T,  -  = T      }
  |
  |  C1-Pair: not covered
  |  C2-Pair: not covered
  |  C3-Pair: not covered
  |  MC/DC Coverage for Decision: 0.00%
  |
  ------------------
    3|      0|        println!("pass");
    4|      1|    }
    5|      1|}
    6|       |
    7|      1|fn main() {
    8|      1|    direct(true, false);
    9|      1|}

It's because rust's "nested decision" mechanism.

As you have checked, "==" and "!=" are not considered as logical operations by rust for now.

So rust first sees the whole statement, which is in form of a == b, and takes it as a decision with only one condition. Let's say it's D1.

Then rust looks into the inner statements, and finds that a is a decision (false && true) && (false == (v2 == false)), which is composed of 3 conditions: the first false, the first true and false == (v2 == false). Note these conditions are organized with only &&. Let's write this decision as D2.

As for b part, it is also a decision (v0 == v2) || (v0 || v0 == v2), with 3 conditions: v0 == v2, v0 and v0==v2. Let's say the decision of b is D3.

In rust's sight, D2 and D3 are nested in D1. But D1 only contains one condition, so it is ignored by mcdc checker. Rust mcdc always ignores decisions with only one condition because it's totally equivalent to branch coverage (Actually we can even prove it's true for decisions with two conditions, but not so clear). Hence only D2 and D3 left and rust shows results as above.

The result is also not right. The reason is the constant issue clarified at #109940 .

Thus the last issue is "==" and "!=" are not recognized as logical operations, same as #109947 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants