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

    <tr>
        <th>Summary</th>
        <td>
            [CoverageMapping] fail to evaluate "constant folded" conditions at compile time
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            tools:llvm-cov
      </td>
    </tr>

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

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

<pre>
    Reduced examples:

```c
#include <stdbool.h>

bool x;
bool y;
bool z;

bool *ptr;

int main(int argc, char **argv) {

    //// Expected ////

    if (x && 1)
        return 1;

    if (x && (&y != (void *) 0))
        return 2;

 //// Not expected ////

    // Fail to evaluate "constant folded" at compile time
    if (x && ((ptr = &y) != (void *) 0))
        return 3;

    // Fail to evaluate "constant folded" at compile time, even though the
    // compiler warns about it.
    if (x && (y, 1))
 return 4;

    // Fail to evaluate "constant folded" at compile time, even though the
    // compiler warns about it.
    if (x && (y != 123))
        return 5;

    // Fail to evaluate "constant folded" at compile time, even though the
    // compiler warns about it.
    if (x && (y == y))
        return 6;
}
```

Compiler explorer [link](https://godbolt.org/#z:OYLghAFBqd5TKALEBjA9gEwKYFFMCWALugE4A0BIEAZgQDbYB2AhgLbYgDkAjF%2BTXRMiAZVQtGIHgBYBQogFUAztgAKAD24AGfgCsp5eiyahUAUgBMAIUtXyKxqiIEh1ZpgDC6egFc2TEAtydwAZAiZsADk/ACNsUhAAZgBOcgAHdCViFyYvX39A9MzsoTCI6LY4hJT7bEdnIREiFlIiPL8AoIdsJxymlqIyqNj4pNSlZtb2gq7JwfDhytGUgEp7dB9SVE4uS0Tw1F8cAGozRI8JzBj0bwA6JDPcMy0AQWeX6%2B9j9TObV8/6McAJ6/d4A44AL1BrzBN0BACo0kRSNC3q9wkRjmwWOEIBjji1gKhyMdUEgWsd4fDCQA3FanADsfzRL2ObOOAHouRzjrh1GkekR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BPxTT0MY%2BjHbPfT/0UyzwUq91IKfRzEvIwJKvcyDwY5atIfSzH93FXbFImXZblwNbd8XWKj7irSKSRhBxAj3PWnoJD6X16QQHwMQMgCpEjqn4HVGm3pyBIGwCwHACQu6jS4ONcgk0NIaVuJZPBhD%2BoDRIWtF%2B3Adp7QOggpqLU2odW6r1fqg1hqYMSM/a2W04FK2OggeAEAUDCTSNBC6EArqRHYDsdQ79P7f0DlXf%2BT14hAPbKQT6jUVj8GFJA9uBgDaiHEJIU2BiLYaGBrbcgIF%2BZpBRo/LgOVyFcO4HDaCIjMTpzfh/L%2BP9bqygASo16aiNFgK8AxbyexYE0J0Ig5BqDRgYKylgiaLVFS3C0MkaQioMlZJydk5IionEbW4fYah8CYnkD4YIkAJBvBiMJKTH2PslCfhAj7PmxgyTYCUI6DAn1MRNJaegNpbBG6oH4A01Qxg6giFaetVGnk%2BKSI4NwGR3j5G/0UQEl6JlgmgO0YQEgei7YGKNsY2QpiVDmOtpYtgQgWAYAgUcgAEo9Kw2BmAvGgugHWzBhTCzuawR5hyyC/L1hNe5GAmiEHBfYIgMLKFwphVMiI9BZnDNhbU%2BgABJTAIB6D0BpGwCO6AaQgO%2BsiD5bpqHWJYLY/K9jHHzM2twAlRKSU0llAon2Qhsb0jWXI3xf9tmqPJWAp5UDIkkjCV5EckStHRIakglBaDqD2OwbgxItxkhaA6jqvVuqajMpKbtfa5SlXNUGrcLJGkeAWC6gtVq0gLDJFSEkjhRSCqIvNYgpJFhOHFO9YdNYEssiuGkEAA)

For decisions in the `/// Not expected ///` section, the second condition can be evaluated to constant at compile time (in some cases, the compiler is indeed aware of that and produces warnings) but their corresponding branch regions are not `0, 0`. As a result, in branch coverage or MC/DC they are not reported as "folded".

On the other hand `gcov` can detect all cases. (Although it totally disregards them and doesn't have a third state like "folded")

cc @evodius96 


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUWEuTo7qS_jXUhrgdWGBsL2oh8TJgsDF-4Z0AWQgwb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