Skip to content

Commit 1a6a463

Browse files
committed
fixup! fixup! fixup! [clang][dataflow] Model conditional operator correctly.
1 parent 86a18d3 commit 1a6a463

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

clang/lib/Analysis/FlowSensitive/Transfer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,18 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
662662
// The conditional operator can evaluate to either of the values of the
663663
// two branches. To model this, join these two values together to yield
664664
// the result of the conditional operator.
665+
// Note: Most joins happen in `computeBlockInputState()`, but this case is
666+
// different:
667+
// - `computeBlockInputState()` (which in turn calls `Environment::join()`
668+
// joins values associated with the _same_ expression or storage
669+
// location, then associates the joined value with that expression or
670+
// storage location. This join has nothing to do with transfer --
671+
// instead, it joins together the results of performing transfer on two
672+
// different blocks.
673+
// - Here, we join values associated with _different_ expressions (the
674+
// true and false branch), then associate the joined value with a third
675+
// expression (the conditional operator itself). This join is what it
676+
// means to perform transfer on the conditional operator.
665677
if (Value *Val = Environment::joinValues(
666678
S->getType(), TrueEnv->getValue(*S->getTrueExpr()), *TrueEnv,
667679
FalseEnv->getValue(*S->getFalseExpr()), *FalseEnv, Env, Model))

0 commit comments

Comments
 (0)