NoQ added a comment.

Thanks for adding me!

Hmm, i think a matcher-based solution would be pretty limited. This is 
definitely your typical all-path data-flow problem because you want to make 
sure that you're looking at the //last// assignment to the variable.

For example:

  int *m = new int;
  m = nullptr;
  if (m == nullptr) { ... } // no-warning

but

  int *m = nullptr;
  m = new int;
  if (m == nullptr) { ... } // expected-warning{{}}

You might be able to fix false positives by adding a condition that the 
variable is not re-assigned within the function (with the help of assignment 
operator or due to taking a non-constant reference to it, etc). But you'll end 
up with a checker that finds a lot less bugs than a full-featured data flow 
analysis could have found. There's a canonical implementation of "the variable 
is not modified" check via ASTMatchers in `LoopUnrolling.cpp`.

If you'll ever want to find a full-featured data flow check, i'm not sure but 
you might be able to re-use `LiveVariables` analysis (the non-`Relaxed` one) to 
find the last assignment, and in this case you won't have to write data flow 
analysis yourself. `DeadStores` checker has an example of that.


Repository:
  rC Clang

https://reviews.llvm.org/D47554



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to