diff options
author | martinboehme <mboehme@google.com> | 2023-10-25 16:02:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-25 16:02:22 +0200 |
commit | d1f59544cf31488d84a2daff0020af2f8e366ed8 (patch) | |
tree | 68bfeecf9388758c3ff2a9f6ea1a271546835f8d /clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp | |
parent | 00b7979946e55ae291dc3e57112d3e5e7892b547 (diff) | |
download | llvm-d1f59544cf31488d84a2daff0020af2f8e366ed8.zip llvm-d1f59544cf31488d84a2daff0020af2f8e366ed8.tar.gz llvm-d1f59544cf31488d84a2daff0020af2f8e366ed8.tar.bz2 |
[clang][dataflow] Add `Environment::allows()`. (#70046)
This allows querying whether, given the flow condition, a certain
formula still
has a solution (though it is not necessarily implied by the flow
condition, as
`flowConditionImplies()` would check).
This can be checked today, but only with a double negation, i.e. to
check
whether, given the flow condition, a formula F has a solution, you can
check
`!Env.flowConditionImplies(Arena.makeNot(F))`. The double negation makes
this
hard to reason about, and it would be nicer to have a way of directly
checking
this.
For consistency, this patch also renames `flowConditionImplies()` to
`proves()`;
the old name is kept around for compatibility but deprecated.
Diffstat (limited to 'clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp')
-rw-r--r-- | clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp index 6a1feb2..40de6cd 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp @@ -145,19 +145,28 @@ Solver::Result DataflowAnalysisContext::querySolver( } bool DataflowAnalysisContext::flowConditionImplies(Atom Token, - const Formula &Val) { + const Formula &F) { // Returns true if and only if truth assignment of the flow condition implies - // that `Val` is also true. We prove whether or not this property holds by + // that `F` is also true. We prove whether or not this property holds by // reducing the problem to satisfiability checking. In other words, we attempt - // to show that assuming `Val` is false makes the constraints induced by the + // to show that assuming `F` is false makes the constraints induced by the // flow condition unsatisfiable. llvm::SetVector<const Formula *> Constraints; Constraints.insert(&arena().makeAtomRef(Token)); - Constraints.insert(&arena().makeNot(Val)); + Constraints.insert(&arena().makeNot(F)); addTransitiveFlowConditionConstraints(Token, Constraints); return isUnsatisfiable(std::move(Constraints)); } +bool DataflowAnalysisContext::flowConditionAllows(Atom Token, + const Formula &F) { + llvm::SetVector<const Formula *> Constraints; + Constraints.insert(&arena().makeAtomRef(Token)); + Constraints.insert(&F); + addTransitiveFlowConditionConstraints(Token, Constraints); + return isSatisfiable(std::move(Constraints)); +} + bool DataflowAnalysisContext::equivalentFormulas(const Formula &Val1, const Formula &Val2) { llvm::SetVector<const Formula *> Constraints; |