[PATCH] D48427: [Analyzer] Fix for D47417 to make the tests pass

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 2 09:39:18 PDT 2018


NoQ added a comment.

That'd be a hell for you because when the container is updated you won't be able to easily find iterators all that iterate over it. Normally what you want to do is keep mapping iterators to container regions, and when the region dies, "freeze" the data (make sure it can no longer be mutated, through an assertion or, ideally, via the type system) and //re-map// the iterator to data directly.

----

I guess you need to track dead containers somehow anyway because you want to find bugs that consist in using iterators from different containers:

  void foo(vector<int> x, vector<int> y) {
    vector::iterator i = x.begin(), e = y.end();   // Both containers are garbage-collected after this statement.
    vector::iterator k = find(i, j, 123);          // Bug: 'i' and 'j' aren't from the same container.
  }

For that purpose i'm fine with tracking dead regions (as long as they aren't marked live, just stored). Or, for enforcing correctness, you could "anonymize" them (i.e., in the container data add an immutable int field that says "this is container #5" and use these ids for your check, then recover the original container region from the identifier in the bug visitor); but i don't think it's necessary.


https://reviews.llvm.org/D48427





More information about the cfe-commits mailing list