@@ -488,14 +488,18 @@ void IteratorChecker::checkLiveSymbols(ProgramStateRef State,
488
488
// alive
489
489
auto RegionMap = State->get <IteratorRegionMap>();
490
490
for (const auto Reg : RegionMap) {
491
- const auto Pos = Reg.second ;
492
- SR.markLive (Pos.getOffset ());
491
+ const auto Offset = Reg.second .getOffset ();
492
+ for (auto i = Offset->symbol_begin (); i != Offset->symbol_end (); ++i)
493
+ if (isa<SymbolData>(*i))
494
+ SR.markLive (*i);
493
495
}
494
496
495
497
auto SymbolMap = State->get <IteratorSymbolMap>();
496
498
for (const auto Sym : SymbolMap) {
497
- const auto Pos = Sym.second ;
498
- SR.markLive (Pos.getOffset ());
499
+ const auto Offset = Sym.second .getOffset ();
500
+ for (auto i = Offset->symbol_begin (); i != Offset->symbol_end (); ++i)
501
+ if (isa<SymbolData>(*i))
502
+ SR.markLive (*i);
499
503
}
500
504
501
505
auto ContMap = State->get <ContainerMap>();
@@ -1157,21 +1161,31 @@ ProgramStateRef relateIteratorPositions(ProgramStateRef State,
1157
1161
const IteratorPosition &Pos2,
1158
1162
bool Equal) {
1159
1163
auto &SVB = State->getStateManager ().getSValBuilder ();
1164
+
1165
+ // FIXME: This code should be reworked as follows:
1166
+ // 1. Subtract the operands using evalBinOp().
1167
+ // 2. Assume that the result doesn't overflow.
1168
+ // 3. Compare the result to 0.
1169
+ // 4. Assume the result of the comparison.
1160
1170
const auto comparison =
1161
1171
SVB.evalBinOp (State, BO_EQ, nonloc::SymbolVal (Pos1.getOffset ()),
1162
- nonloc::SymbolVal (Pos2.getOffset ()), SVB.getConditionType ())
1163
- .getAs <DefinedSVal>();
1164
-
1165
- if (comparison) {
1166
- auto NewState = State->assume (*comparison, Equal);
1167
- if (const auto CompSym = comparison->getAsSymbol ()) {
1168
- return assumeNoOverflow (NewState, cast<SymIntExpr>(CompSym)->getLHS (), 2 );
1169
- }
1170
-
1171
- return NewState;
1172
+ nonloc::SymbolVal (Pos2.getOffset ()),
1173
+ SVB.getConditionType ());
1174
+
1175
+ assert (comparison.getAs <DefinedSVal>() &&
1176
+ " Symbol comparison must be a `DefinedSVal`" );
1177
+
1178
+ auto NewState = State->assume (comparison.castAs <DefinedSVal>(), Equal);
1179
+ if (const auto CompSym = comparison.getAsSymbol ()) {
1180
+ assert (isa<SymIntExpr>(CompSym) &&
1181
+ " Symbol comparison must be a `SymIntExpr`" );
1182
+ assert (BinaryOperator::isComparisonOp (
1183
+ cast<SymIntExpr>(CompSym)->getOpcode ()) &&
1184
+ " Symbol comparison must be a comparison" );
1185
+ return assumeNoOverflow (NewState, cast<SymIntExpr>(CompSym)->getLHS (), 2 );
1172
1186
}
1173
1187
1174
- return State ;
1188
+ return NewState ;
1175
1189
}
1176
1190
1177
1191
bool isZero (ProgramStateRef State, const NonLoc &Val) {
@@ -1225,14 +1239,12 @@ bool compare(ProgramStateRef State, NonLoc NL1, NonLoc NL2,
1225
1239
auto &SVB = State->getStateManager ().getSValBuilder ();
1226
1240
1227
1241
const auto comparison =
1228
- SVB.evalBinOp (State, Opc, NL1, NL2, SVB.getConditionType ())
1229
- .getAs <DefinedSVal>();
1242
+ SVB.evalBinOp (State, Opc, NL1, NL2, SVB.getConditionType ());
1230
1243
1231
- if (comparison) {
1232
- return !State->assume (*comparison, false );
1233
- }
1244
+ assert (comparison.getAs <DefinedSVal>() &&
1245
+ " Symbol comparison must be a `DefinedSVal`" );
1234
1246
1235
- return false ;
1247
+ return !State-> assume (comparison. castAs <DefinedSVal>(), false ) ;
1236
1248
}
1237
1249
1238
1250
} // namespace
0 commit comments