[PATCH] D106285: [Analyzer][solver] Fix inconsistent equivalence class data
Gabor Marton via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 23 05:26:07 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG44fa31fa6da0: [Analyzer][solver] Fix inconsistent equivalence class data (authored by martong).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D106285/new/
https://reviews.llvm.org/D106285
Files:
clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
clang/test/Analysis/solver-sym-simplification-no-crash2.c
Index: clang/test/Analysis/solver-sym-simplification-no-crash2.c
===================================================================
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-no-crash2.c
@@ -0,0 +1,23 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN: -analyzer-checker=core \
+// RUN: -analyzer-checker=debug.ExprInspection \
+// RUN: -verify
+
+// Here, we test that symbol simplification in the solver does not produce any
+// crashes.
+// https://bugs.llvm.org/show_bug.cgi?id=51109
+
+// expected-no-diagnostics
+
+int a, b, c, d;
+void f() {
+ a = -1;
+ d = b * a;
+ a = d / c;
+ if (a < 7 / b)
+ return;
+ if (d *a / c < 7 / b)
+ return;
+ if (b == 1 && c == -1)
+ return;
+}
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -600,9 +600,10 @@
areEqual(ProgramStateRef State, SymbolRef First, SymbolRef Second);
/// Iterate over all symbols and try to simplify them.
- LLVM_NODISCARD ProgramStateRef simplify(SValBuilder &SVB,
- RangeSet::Factory &F,
- ProgramStateRef State);
+ LLVM_NODISCARD static inline ProgramStateRef simplify(SValBuilder &SVB,
+ RangeSet::Factory &F,
+ ProgramStateRef State,
+ EquivalenceClass Class);
void dumpToStream(ProgramStateRef State, raw_ostream &os) const;
LLVM_DUMP_METHOD void dump(ProgramStateRef State) const {
@@ -1696,7 +1697,7 @@
ClassMembersTy Members = State->get<ClassMembers>();
for (std::pair<EquivalenceClass, SymbolSet> ClassToSymbolSet : Members) {
EquivalenceClass Class = ClassToSymbolSet.first;
- State = Class.simplify(Builder, RangeFactory, State);
+ State = EquivalenceClass::simplify(Builder, RangeFactory, State, Class);
if (!State)
return false;
SimplifiedClasses.insert(Class);
@@ -1710,7 +1711,7 @@
EquivalenceClass Class = ClassConstraint.first;
if (SimplifiedClasses.count(Class)) // Already simplified.
continue;
- State = Class.simplify(Builder, RangeFactory, State);
+ State = EquivalenceClass::simplify(Builder, RangeFactory, State, Class);
if (!State)
return false;
}
@@ -2090,18 +2091,17 @@
// class to this class. This way, we simplify not just the symbols but the
// classes as well: we strive to keep the number of the classes to be the
// absolute minimum.
-LLVM_NODISCARD ProgramStateRef EquivalenceClass::simplify(
- SValBuilder &SVB, RangeSet::Factory &F, ProgramStateRef State) {
- SymbolSet ClassMembers = getClassMembers(State);
+LLVM_NODISCARD ProgramStateRef
+EquivalenceClass::simplify(SValBuilder &SVB, RangeSet::Factory &F,
+ ProgramStateRef State, EquivalenceClass Class) {
+ SymbolSet ClassMembers = Class.getClassMembers(State);
for (const SymbolRef &MemberSym : ClassMembers) {
SymbolRef SimplifiedMemberSym = ento::simplify(State, MemberSym);
if (SimplifiedMemberSym && MemberSym != SimplifiedMemberSym) {
- EquivalenceClass ClassOfSimplifiedSym =
- EquivalenceClass::find(State, SimplifiedMemberSym);
// The simplified symbol should be the member of the original Class,
// however, it might be in another existing class at the moment. We
// have to merge these classes.
- State = merge(F, State, ClassOfSimplifiedSym);
+ State = merge(F, State, MemberSym, SimplifiedMemberSym);
if (!State)
return nullptr;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106285.361164.patch
Type: text/x-patch
Size: 3799 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210723/a2ab86e8/attachment.bin>
More information about the cfe-commits
mailing list