[clang][dataflow] Fix crash when having boolean-to-integral casts.
authorJun Zhang <jun@junz.org>
Thu, 29 Dec 2022 06:40:40 +0000 (14:40 +0800)
committerJun Zhang <jun@junz.org>
Fri, 30 Dec 2022 05:14:44 +0000 (13:14 +0800)
commiteda2eaabf2949c08ba94c92b9aad6fccb3c8eaa2
tree7cf09abc7228bb63517e2daef88cd831e8368fc3
parent5d4cebfa5287fe9ba73e78c4028f673f1706eefd
[clang][dataflow] Fix crash when having boolean-to-integral casts.

Since now we just ignore all (implicit) integral casts, treating the
resulting value as the same as the underlying value, it could cause
inconsistency between values after `Join` if in some paths the type
doesn't strictly match. This could cause intermittent crashes.

std::optional<bool> o;
int x;
if (o.has_value()) {
  x = o.value();
}

Fixes: https://github.com/llvm/llvm-project/issues/59728

Signed-off-by: Jun Zhang <jun@junz.org>
Differential Revision: https://reviews.llvm.org/D140753
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp