]> granicus.if.org Git - clang/commit
[Analyzer] Iterator Checker - Forbid decrements past the begin() and increments past...
authorAdam Balogh <adam.balogh@ericsson.com>
Tue, 4 Dec 2018 10:27:27 +0000 (10:27 +0000)
committerAdam Balogh <adam.balogh@ericsson.com>
Tue, 4 Dec 2018 10:27:27 +0000 (10:27 +0000)
commitdee7e8f8d4d0265a262e5cbd721071fbfb9eaf7c
treecc6c390ba6d01a0b496947b428040f97524ab819
parentf9accceeaa5ef6b194d509949964d336e97be9ea
[Analyzer] Iterator Checker - Forbid decrements past the begin() and increments past the end() of containers

Previously, the iterator range checker only warned upon dereferencing of
iterators outside their valid range as well as increments and decrements of
out-of-range iterators where the result remains out-of-range. However, the C++
standard is more strict than this: decrementing begin() or incrementing end()
results in undefined behaviour even if the iterator is not dereferenced
afterwards. Coming back to the range once out-of-range is also undefined.

This patch corrects the behaviour of the iterator range checker: warnings are
given for any operation whose result is ahead of begin() or past the end()
(which is the past-end iterator itself, thus now we are speaking of past
past-the-end).

Differential Revision: https://reviews.llvm.org/D53812

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348245 91177308-0d34-0410-b5e6-96231b3b80d8
lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
test/Analysis/iterator-range.cpp