diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h --- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h +++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h @@ -198,7 +198,7 @@ /// calls. void addTransitiveFlowConditionConstraints( AtomicBoolValue &Token, llvm::DenseSet &Constraints, - llvm::DenseSet &VisitedTokens) const; + llvm::DenseSet &VisitedTokens); std::unique_ptr S; @@ -232,21 +232,16 @@ // defines the flow condition. Conceptually, each binding corresponds to an // "iff" of the form `FC <=> (C1 ^ C2 ^ ...)` where `FC` is a flow condition // token (an atomic boolean) and `Ci`s are the set of constraints in the flow - // flow condition clause. Internally, we do not record the formula directly as - // an "iff". Instead, a flow condition clause is encoded as conjuncts of the - // form `(FC v !C1 v !C2 v ...) ^ (C1 v !FC) ^ (C2 v !FC) ^ ...`. The first - // conjuct is stored in the `FlowConditionFirstConjuncts` map and the set of - // remaining conjuncts are stored in the `FlowConditionRemainingConjuncts` - // map, both keyed by the token of the flow condition. + // flow condition clause. The set of constraints (C1 ^ C2 ^ ...) are stored in + // the `FlowConditionConstraints` map, keyed by the token of the flow + // condition. // // Flow conditions depend on other flow conditions if they are created using // `forkFlowCondition` or `joinFlowConditions`. The graph of flow condition // dependencies is stored in the `FlowConditionDeps` map. llvm::DenseMap> FlowConditionDeps; - llvm::DenseMap FlowConditionFirstConjuncts; - llvm::DenseMap> - FlowConditionRemainingConjuncts; + llvm::DenseMap FlowConditionConstraints; }; } // namespace dataflow diff --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp --- a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp @@ -66,19 +66,16 @@ } AtomicBoolValue &DataflowAnalysisContext::makeFlowConditionToken() { - AtomicBoolValue &Token = createAtomicBoolValue(); - FlowConditionRemainingConjuncts[&Token] = {}; - FlowConditionFirstConjuncts[&Token] = &Token; - return Token; + return createAtomicBoolValue(); } void DataflowAnalysisContext::addFlowConditionConstraint( AtomicBoolValue &Token, BoolValue &Constraint) { - FlowConditionRemainingConjuncts[&Token].insert(&getOrCreateDisjunctionValue( - Constraint, getOrCreateNegationValue(Token))); - FlowConditionFirstConjuncts[&Token] = - &getOrCreateDisjunctionValue(*FlowConditionFirstConjuncts[&Token], - getOrCreateNegationValue(Constraint)); + auto Res = FlowConditionConstraints.try_emplace(&Token, &Constraint); + if (!Res.second) { + Res.first->second = + &getOrCreateConjunctionValue(*Res.first->second, Constraint); + } } AtomicBoolValue & @@ -133,24 +130,30 @@ void DataflowAnalysisContext::addTransitiveFlowConditionConstraints( AtomicBoolValue &Token, llvm::DenseSet &Constraints, - llvm::DenseSet &VisitedTokens) const { + llvm::DenseSet &VisitedTokens) { auto Res = VisitedTokens.insert(&Token); if (!Res.second) return; - auto FirstConjunctIT = FlowConditionFirstConjuncts.find(&Token); - if (FirstConjunctIT != FlowConditionFirstConjuncts.end()) - Constraints.insert(FirstConjunctIT->second); - auto RemainingConjunctsIT = FlowConditionRemainingConjuncts.find(&Token); - if (RemainingConjunctsIT != FlowConditionRemainingConjuncts.end()) - Constraints.insert(RemainingConjunctsIT->second.begin(), - RemainingConjunctsIT->second.end()); + auto ConstraintsIT = FlowConditionConstraints.find(&Token); + if (ConstraintsIT == FlowConditionConstraints.end()) { + Constraints.insert(&Token); + } else { + // Bind flow condition token via `iff` to its set of constraints: + // FC <=> (C1 ^ C2 ^ ...), where Ci are constraints + Constraints.insert(&getOrCreateConjunctionValue( + getOrCreateDisjunctionValue( + Token, getOrCreateNegationValue(*ConstraintsIT->second)), + getOrCreateDisjunctionValue(getOrCreateNegationValue(Token), + *ConstraintsIT->second))); + } auto DepsIT = FlowConditionDeps.find(&Token); if (DepsIT != FlowConditionDeps.end()) { - for (AtomicBoolValue *DepToken : DepsIT->second) + for (AtomicBoolValue *DepToken : DepsIT->second) { addTransitiveFlowConditionConstraints(*DepToken, Constraints, VisitedTokens); + } } }