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

    <tr>
        <th>Summary</th>
        <td>
            [clang][dataflow] Don't associate `BoolValue`s with expressions / locations of integer type
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:dataflow
      </td>
    </tr>

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

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

<pre>
    As explained [here](https://github.com/llvm/llvm-project/blob/ed6e6afd5938e7d04862eb5ae2d09eb723663f25/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp#L123), a boolean-to-integer cast currently just forwards the `BoolValue`, so we can end up with `BoolValue`s that are associated with expressions or locations of integer type.

As a result, [`joinDistinctValues()`](https://github.com/llvm/llvm-project/blob/ed6e6afd5938e7d04862eb5ae2d09eb723663f25/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp#L123) and [`widenDistinctValues()`](https://github.com/llvm/llvm-project/blob/ed6e6afd5938e7d04862eb5ae2d09eb723663f25/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp#L161) need to defensively check that both values they operate on are `BoolValue`s. It also just seems wrong to associate a `BoolValue` with an integer expression or location.

I think the right thing to do would be to create a fresh `IntegerValue` when we see an `IntegralCast`.

The only snag here is that this would break the test [`IntegralToBooleanCastFromBool`](https://github.com/llvm/llvm-project/blob/e400e908b2d97529b1a65dd0bdad80d481c39527/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp#L3395C20-L3395C49).

This test currently tests that we can round-trip cast a bool to an integer and back again and obtain the same `BoolValue` that we started out with. This behavior would obviously be broken if we created a fresh `IntegerValue` for an `IntegralCast`.

I'm not sure if we're actually relying on this round-trip behavior for anything, but we should check before we change this.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcls1u67gOx59G2RANFDl24kUW6ckNUODu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