Issue 90024
Summary [clang][dataflow] Don't associate `BoolValue`s with expressions / locations of integer type
Labels clang:dataflow
Assignees
Reporter martinboehme
    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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to