diff --git a/clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp --- a/clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp @@ -402,7 +402,7 @@ if (!Cont) return; - // At least one of the iterators have recorded positions. If one of them has + // At least one of the iterators has recorded positions. If one of them does // not then create a new symbol for the offset. SymbolRef Sym; if (!LPos || !RPos) { @@ -422,7 +422,7 @@ RPos = getIteratorPosition(State, RVal); } - // We cannot make assumpotions on `UnknownVal`. Let us conjure a symbol + // We cannot make assumptions on `UnknownVal`. Let us conjure a symbol // instead. if (RetVal.isUnknown()) { auto &SymMgr = C.getSymbolManager(); @@ -532,8 +532,9 @@ return; const auto *value = &RHS; + SVal val; if (auto loc = RHS.getAs()) { - const auto val = State->getRawSVal(*loc); + val = State->getRawSVal(*loc); value = &val; } diff --git a/clang/test/Analysis/iterator-range.cpp b/clang/test/Analysis/iterator-range.cpp --- a/clang/test/Analysis/iterator-range.cpp +++ b/clang/test/Analysis/iterator-range.cpp @@ -810,6 +810,19 @@ auto j = std::prev(i, 0); // no-warning } +// std::prev() with int* for checking Loc value argument +namespace std { +template +T prev(T, int *); +} + +void prev_loc_value(const std::vector &V, int o) { + + auto i = return_any_iterator(V.begin()); + int *offset = &o; + auto j = std::prev(i, offset); // no-warning +} + // // Structure member dereference operators //