diff options
author | martinboehme <mboehme@google.com> | 2024-04-25 09:24:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-25 09:24:08 +0200 |
commit | b9208ce318907b1a5ea4ad0d2aa4414dfba0616c (patch) | |
tree | 7cd4f221c17c2cce53114dbf694c421668edbc1d /clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp | |
parent | 9b0651f5ae6510577302ea527b2cc79e80ec9ccc (diff) | |
download | llvm-b9208ce318907b1a5ea4ad0d2aa4414dfba0616c.zip llvm-b9208ce318907b1a5ea4ad0d2aa4414dfba0616c.tar.gz llvm-b9208ce318907b1a5ea4ad0d2aa4414dfba0616c.tar.bz2 |
[clang][dataflow] Crash fix for `widenDistinctValues()`. (#89895)
We used to crash if the previous iteration contained a `BoolValue` and
the
current iteration contained an `IntegerValue`. The accompanying test
sets up
this situation -- see comments there for details.
While I'm here, clean up the tests for integral casts to use the test
helpers we
have available now. I was looking at these tests to understand how we
handle
integral casts, and the test helpers make the tests easier to read.
Diffstat (limited to 'clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp')
-rw-r--r-- | clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp index 636d230..d79e734 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -157,7 +157,13 @@ static WidenResult widenDistinctValues(QualType Type, Value &Prev, Value &Current, Environment &CurrentEnv, Environment::ValueModel &Model) { // Boolean-model widening. - if (auto *PrevBool = dyn_cast<BoolValue>(&Prev)) { + if (isa<BoolValue>(Prev) && isa<BoolValue>(Current)) { + // FIXME: Checking both values should be unnecessary, but we can currently + // end up with `BoolValue`s in integer-typed variables. See comment in + // `joinDistinctValues()` for details. + auto &PrevBool = cast<BoolValue>(Prev); + auto &CurBool = cast<BoolValue>(Current); + if (isa<TopBoolValue>(Prev)) // Safe to return `Prev` here, because Top is never dependent on the // environment. @@ -166,13 +172,12 @@ static WidenResult widenDistinctValues(QualType Type, Value &Prev, // We may need to widen to Top, but before we do so, check whether both // values are implied to be either true or false in the current environment. // In that case, we can simply return a literal instead. - auto &CurBool = cast<BoolValue>(Current); - bool TruePrev = PrevEnv.proves(PrevBool->formula()); + bool TruePrev = PrevEnv.proves(PrevBool.formula()); bool TrueCur = CurrentEnv.proves(CurBool.formula()); if (TruePrev && TrueCur) return {&CurrentEnv.getBoolLiteralValue(true), LatticeEffect::Unchanged}; if (!TruePrev && !TrueCur && - PrevEnv.proves(PrevEnv.arena().makeNot(PrevBool->formula())) && + PrevEnv.proves(PrevEnv.arena().makeNot(PrevBool.formula())) && CurrentEnv.proves(CurrentEnv.arena().makeNot(CurBool.formula()))) return {&CurrentEnv.getBoolLiteralValue(false), LatticeEffect::Unchanged}; |