[PATCH] D82185: [Analyzer][WIP] Handle pointer implemented as iterators in iterator checkers

Balogh, Ádám via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 19 07:32:42 PDT 2020


baloghadamsoftware created this revision.
baloghadamsoftware added reviewers: NoQ, Szelethus, martong, gamesh411.
baloghadamsoftware added a project: clang.
Herald added subscribers: ASDenysPetrov, steakhal, Charusso, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, xazax.hun, whisperity.
baloghadamsoftware marked an inline comment as done.
baloghadamsoftware added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp:256
+  SVal SubVal = State->getSVal(UO->getSubExpr(), C.getLocationContext());
+  SVal Result = State->getSVal(UO, C.getLocationContext());
+
----------------
This is the problematic point which is not working. I left the comments intentionally in the code.

The problem is that in `postStmt` we are //after//  the operation. Thus the value of the operand (`SubExpr`) is not `i` anymore, but the //former value// of `i` (a pointer to a symbolic region initially). Instead, the result is `i` in case of prefix operators, but also the former value in case of postfix operators. This is correct, of course, because here, after the call the value of `i` was changed, thus it is not equal to the parameter. However, we need the region of `i` here and/or the new value bound to it (e.g. the pointer to an element region which is usually the result of a `++` or `--` on a pointer to a symbolic region). How to reach that? Of course, in `preStmt` the operand is `i` as it should be. The same is true for binary operators `+=` and `-=`. 


Iterators are an abstraction of pointers and in some data structures iterators may be implemented by pointers. This patch adds support for iterators implemented as pointers in all the iterator checkers (including iterator modeling).

This patch is work in progress, modeling of lvalue operations do not work yet.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82185

Files:
  clang/lib/StaticAnalyzer/Checkers/InvalidatedIteratorChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/Iterator.cpp
  clang/lib/StaticAnalyzer/Checkers/Iterator.h
  clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
  clang/test/Analysis/invalidated-iterator.cpp
  clang/test/Analysis/iterator-modeling.cpp
  clang/test/Analysis/iterator-range.cpp
  clang/test/Analysis/mismatched-iterator.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82185.272058.patch
Type: text/x-patch
Size: 29589 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200619/167aa8bf/attachment-0001.bin>


More information about the cfe-commits mailing list