[PATCH] D53812: [Analyzer] Iterator Checker - Forbid increments past the begin() and decrements past the end() of containers

Balogh, Ádám via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 29 05:03:58 PDT 2018


baloghadamsoftware created this revision.
baloghadamsoftware added a reviewer: NoQ.
baloghadamsoftware added a project: clang.
Herald added subscribers: donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, whisperity.
Herald added a reviewer: george.karpenkov.

Previously, the iterator range checker only warned upon dereference 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 inrementing `end()` results in undefined behavior even if the iterator is not dereferenced afterward. Coming back to the range once out-of-range is also undefined.

This patch corrects the behavior 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-end).


Repository:
  rC Clang

https://reviews.llvm.org/D53812

Files:
  lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
  test/Analysis/iterator-range.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53812.171486.patch
Type: text/x-patch
Size: 14241 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181029/563ccaa8/attachment.bin>


More information about the cfe-commits mailing list