This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Generate readable form of input and output of satisfiability checking for debugging purposes.
ClosedPublic

Authored by wyt on Jul 12 2022, 1:49 AM.

Details

Summary

As part of the dataflow analysis framework, there is a SAT solver (API defined in Solver.h) which takes llvm::DenseSet<BoolValue*> Constraints as input and checks if the booleans are satisfiable.
This patch implements functionality to produce a readable string representation of the boolean constraints, the status of the SAT check and the satisfying truth assigment if found by the SAT solver.

Note that the booleans in an llvm::DenseSet is not fixed. Therefore, we introduce an overloaded debugString which takes a std::vector<BoolValue *> Constraints as input to guarantee order stability and enable testing against hardcoded expected string values.

Depends On D129547

Diff Detail

Event Timeline

wyt created this revision.Jul 12 2022, 1:49 AM
Herald added a project: Restricted Project. · View Herald Transcript
wyt requested review of this revision.Jul 12 2022, 1:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 12 2022, 1:49 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
wyt retitled this revision from [clang][dataflow] Generate readable form of input and output of satisfiability checking. to [clang][dataflow] Generate readable form of input and output of satisfiability checking for debugging purposes..Jul 12 2022, 2:26 AM
wyt edited the summary of this revision. (Show Details)
wyt updated this revision to Diff 443917.Jul 12 2022, 5:07 AM

Use std::vector as input to debugString to maintain order stability of boolean constraints to enable testing. debugString which takes a llvm::DenseSet<BoolValue*> is now a wrapper around the logic applied to std::vector.

wyt edited the summary of this revision. (Show Details)Jul 12 2022, 6:06 AM
wyt edited the summary of this revision. (Show Details)
gribozavr2 added inline comments.Jul 12 2022, 6:21 AM
clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
140

I appreciate the table, but it looks quite bulky... Could we switch to a simple atom=value\natom2=value2\n format?

144–153

We put the llvm_unreachable after the switch, so that clang can warn us if we add a new enumerator but forget to update the switch. Please apply everywhere in this patch stack.

156
wyt updated this revision to Diff 443941.Jul 12 2022, 7:47 AM
wyt marked 2 inline comments as done.

Address comments.

wyt updated this revision to Diff 443947.Jul 12 2022, 8:02 AM

Fix comment, remove unused import.

wyt updated this revision to Diff 443971.Jul 12 2022, 8:52 AM

Remove unnecessary enum keyword.

wyt marked an inline comment as done.Jul 12 2022, 8:56 AM
wyt updated this revision to Diff 443983.Jul 12 2022, 9:13 AM

Change propagated from parent patch.

xazax.hun accepted this revision.Jul 12 2022, 9:21 AM

Some nits inline, but looks good to me.

clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
116–130

In its current form, I think you could create the final strings in one step and sort those strings instead of the pairs. Or do we expect alignment to mess up the order in that case?

clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
415

I don't see a test case for Unsatisfiable constraints.

This revision is now accepted and ready to land.Jul 12 2022, 9:21 AM
gribozavr2 accepted this revision.Jul 12 2022, 9:27 AM
gribozavr2 added inline comments.
clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
45–52
wyt updated this revision to Diff 444030.Jul 12 2022, 11:39 AM
wyt marked 3 inline comments as done.

Address comments.

wyt added a comment.Jul 12 2022, 11:44 AM
clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
116–130

In its current form, I think you could create the final strings in one step and sort those strings instead of the pairs. Or do we expect alignment to mess up the order in that case?

Removed LinesData and the intermediate step of storing a pair of strings. There is still a loop at the start of the function to find the max name length for alignment purposes.

clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
228

@xazax.hun

I don't see a test case for Unsatisfiable constraints.

Here.

xazax.hun accepted this revision.Jul 12 2022, 11:54 AM
xazax.hun added inline comments.
clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
228

Whoops, indeed. Sorry :)

This revision was landed with ongoing or failed builds.Jul 13 2022, 4:59 AM
This revision was automatically updated to reflect the committed changes.