This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Return a solution from the solver when `Constraints` are `Satisfiable`.
ClosedPublic

Authored by wyt on Jul 6 2022, 2:42 AM.

Details

Summary

A truth assignment to atomic boolean values which satisfy Constraints will be returned if found by the solver.
This gives us more information which can be helpful for debugging or constructing warning messages.

Diff Detail

Event Timeline

wyt created this revision.Jul 6 2022, 2:42 AM
Herald added a project: Restricted Project. · View Herald Transcript
wyt requested review of this revision.Jul 6 2022, 2:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 6 2022, 2:42 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
wyt edited the summary of this revision. (Show Details)Jul 6 2022, 2:49 AM
gribozavr2 added inline comments.Jul 6 2022, 3:30 AM
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
273–278

I'd suggest to revert these edits. Vertical alignment that is not supported by an autoformatter isn't sustainable.

sgatev added inline comments.Jul 6 2022, 5:46 AM
clang/include/clang/Analysis/FlowSensitive/Solver.h
46

A solution consists of true/false assignments for all variables. Having an Unassigned option seems confusing. I suggest defining only two values in this enum and translating WatchedLiteralsSolver's internal representation to Solution right before returning it, in buildValAssignment.

51–58

Let's document these members.

wyt updated this revision to Diff 442824.Jul 7 2022, 2:17 AM

Address comments.

wyt updated this revision to Diff 442825.Jul 7 2022, 2:20 AM
wyt marked 3 inline comments as done.

Typo fix.

wyt updated this revision to Diff 442828.Jul 7 2022, 2:42 AM

Make scope resolution consistent (Solver:: instead of WatchedLiteralsSolver::).

gribozavr2 accepted this revision.Jul 7 2022, 2:57 AM
gribozavr2 added inline comments.
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
278
This revision is now accepted and ready to land.Jul 7 2022, 2:57 AM
sgatev accepted this revision.Jul 7 2022, 3:00 AM
sgatev added inline comments.
clang/include/clang/Analysis/FlowSensitive/Solver.h
79

#include "llvm/ADT/DenseMap.h"

clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
201

Let's create a local Var variable initialized to NextVar and use that here and below, where NextVar - 1 is currently used.

472–473
wyt updated this revision to Diff 442840.Jul 7 2022, 3:17 AM
wyt marked 3 inline comments as done.

Address comments.

wyt updated this revision to Diff 442845.Jul 7 2022, 3:23 AM

Fix comment.

wyt marked an inline comment as done.Jul 7 2022, 3:24 AM
gribozavr2 accepted this revision.Jul 7 2022, 3:35 AM
gribozavr2 added inline comments.
clang/include/clang/Analysis/FlowSensitive/Solver.h
67

Please use llvm::Optional, we can't use std::optional in LLVM/Clang code yet.

wyt updated this revision to Diff 442848.Jul 7 2022, 3:45 AM

Replace std::optional with llvm::Optional

wyt marked an inline comment as done.Jul 7 2022, 3:46 AM
hlopko accepted this revision.Jul 7 2022, 5:03 AM
wyt updated this revision to Diff 442874.Jul 7 2022, 5:45 AM

Remove decomposing declarations which are not available in llvm.

This revision was landed with ongoing or failed builds.Jul 7 2022, 11:54 AM
This revision was automatically updated to reflect the committed changes.
dyung added a subscriber: dyung.Jul 7 2022, 12:35 PM

This change is causing a build failure on the Windows PS4 bot, can you please take a look and revert if you need time to investigate?

https://lab.llvm.org/buildbot/#/builders/216/builds/7026

FAILED: tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/WatchedLiteralsSolver.cpp.obj 
C:\PROGRA~2\MICROS~1\2019\BUILDT~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\cl.exe  /nologo /TP -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GNU_SOURCE -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools\clang\lib\Analysis\FlowSensitive -IC:\buildbot-root\llvm-clang-x86_64-sie-win\llvm-project\clang\lib\Analysis\FlowSensitive -IC:\buildbot-root\llvm-clang-x86_64-sie-win\llvm-project\clang\include -Itools\clang\include -Iinclude -IC:\buildbot-root\llvm-clang-x86_64-sie-win\llvm-project\llvm\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:__cplusplus /Oi /bigobj /permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd4324 -w14062 -we4238 /Gw /MD /O2 /Ob2  /EHs-c- /GR- -UNDEBUG -std:c++14 /showIncludes /Fotools\clang\lib\Analysis\FlowSensitive\CMakeFiles\obj.clangAnalysisFlowSensitive.dir\WatchedLiteralsSolver.cpp.obj /Fdtools\clang\lib\Analysis\FlowSensitive\CMakeFiles\obj.clangAnalysisFlowSensitive.dir\ /FS -c C:\buildbot-root\llvm-clang-x86_64-sie-win\llvm-project\clang\lib\Analysis\FlowSensitive\WatchedLiteralsSolver.cpp
C:\buildbot-root\llvm-clang-x86_64-sie-win\llvm-project\clang\lib\Analysis\FlowSensitive\WatchedLiteralsSolver.cpp(477): error C2429: language feature 'structured bindings' requires compiler flag '/std:c++17'