<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/93560>93560</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Coverage][MC/DC] Constant folding might make conditions never covered
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Lambdaris
      </td>
    </tr>
</table>

<pre>
    Let's consider such code:
```c++
constexpr bool constant_bool() { return false; }

int mcdc_with_constant(bool a) {
  if (a && constant_bool()) {
    return 1;
  } else {
    return 0;
 }
}
```
Because the decision cannot be evaluated to `true`, no condition could be shown to be covered by MCDC.

The constant may be a template parameter or a platform-dependent variable. As a result, one of the two branches might be optimized out and  there is no branch in practice.

So could we eliminate such conditions and decisions from mcdc? For example,

* For `a && CONST`, if `CONST==false`, condition `a` is treated as `folded` too.
* For `a || CONST`, if `CONST==true`, `a` will be taken as folded.
* For `a && (b || CONST)`, if `CONST==true`, `b` is taken as folded.

Also if a decision can not be evaluated to the other value, we mark it as folded.

We can check value of `CONST` in mcdc as long as the front end preserves the non-zero counter. For now clang assign `Zero` to both  `Counter` and `FalseCounter` if the condition was constant. By only setting the never reached counter to zero, we can ensure the constant is `true` if its `FalseCounter` is `Zero` and vice versa. Then by analyzing the decision tree, we can also find out which conditions would never be covered in meaning of mcdc and mark them as folded too.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVU2P4zYM_TXKhZjAkRPbOeQwcZDTbnvYBQr0spAlOlZHlgJJTjb76wtK-ZoiLQoEdkyJfI_koyRC0AeLuGGrLVvtZmKKg_ObL2LslPA6zDqnLpsvGBmvA0hng1boIUxyAOkUsvKdFTtWvLOqyD_J-JZ-yUoOEX8ePXTOmeQfhY0_6IvxhvE1sHoLHuPkLfTCBGTlFli9u0ZNT20jjFLJH2cdhx-3IIw3Kai4R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