[PATCH] D48764: [Analyzer] Hotfix for iterator checkers: Mark left-hand side of `SymIntExpr` objects as live in the program state maps.
Balogh, Ádám via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 2 05:50:32 PDT 2018
baloghadamsoftware updated this revision to Diff 153698.
baloghadamsoftware added a comment.
Updated according to the comments and assertions added to fail the tests without the fix.
https://reviews.llvm.org/D48764
Files:
lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
Index: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
+++ lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
@@ -488,14 +488,16 @@
// alive
auto RegionMap = State->get<IteratorRegionMap>();
for (const auto Reg : RegionMap) {
- const auto Pos = Reg.second;
- SR.markLive(Pos.getOffset());
+ const auto Offset = Reg.second.getOffset();
+ for (auto i = Offset->symbol_begin(); i != Offset->symbol_end(); ++i)
+ SR.markLive(*i);
}
auto SymbolMap = State->get<IteratorSymbolMap>();
for (const auto Sym : SymbolMap) {
- const auto Pos = Sym.second;
- SR.markLive(Pos.getOffset());
+ const auto Offset = Sym.second.getOffset();
+ for (auto i = Offset->symbol_begin(); i != Offset->symbol_end(); ++i)
+ SR.markLive(*i);
}
auto ContMap = State->get<ContainerMap>();
@@ -1159,19 +1161,23 @@
auto &SVB = State->getStateManager().getSValBuilder();
const auto comparison =
SVB.evalBinOp(State, BO_EQ, nonloc::SymbolVal(Pos1.getOffset()),
- nonloc::SymbolVal(Pos2.getOffset()), SVB.getConditionType())
- .getAs<DefinedSVal>();
-
- if (comparison) {
- auto NewState = State->assume(*comparison, Equal);
- if (const auto CompSym = comparison->getAsSymbol()) {
- return assumeNoOverflow(NewState, cast<SymIntExpr>(CompSym)->getLHS(), 2);
- }
-
- return NewState;
+ nonloc::SymbolVal(Pos2.getOffset()),
+ SVB.getConditionType());
+
+ assert(comparison.getAs<DefinedSVal>() &&
+ "Symbol comparison must by a `DefinedSVal`");
+
+ auto NewState = State->assume(comparison.castAs<DefinedSVal>(), Equal);
+ if (const auto CompSym = comparison.getAsSymbol()) {
+ assert(isa<SymIntExpr>(CompSym) &&
+ "Symbol comparison must be a `SymIntExpr`");
+ assert(BinaryOperator::isComparisonOp(
+ cast<SymIntExpr>(CompSym)->getOpcode()) &&
+ "Symbol comparison must be a comparison");
+ return assumeNoOverflow(NewState, cast<SymIntExpr>(CompSym)->getLHS(), 2);
}
- return State;
+ return NewState;
}
bool isZero(ProgramStateRef State, const NonLoc &Val) {
@@ -1225,14 +1231,12 @@
auto &SVB = State->getStateManager().getSValBuilder();
const auto comparison =
- SVB.evalBinOp(State, Opc, NL1, NL2, SVB.getConditionType())
- .getAs<DefinedSVal>();
+ SVB.evalBinOp(State, Opc, NL1, NL2, SVB.getConditionType());
- if (comparison) {
- return !State->assume(*comparison, false);
- }
+ assert(comparison.getAs<DefinedSVal>() &&
+ "Symbol comparison must by a `DefinedSVal`");
- return false;
+ return !State->assume(comparison.castAs<DefinedSVal>(), false);
}
} // namespace
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48764.153698.patch
Type: text/x-patch
Size: 2818 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180702/fa3069d1/attachment-0001.bin>
More information about the cfe-commits
mailing list