[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

Deep Majumder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 25 06:09:16 PDT 2021


RedDocMD marked 3 inline comments as done.
RedDocMD added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp:106-109
+    if (const auto *DS = llvm::dyn_cast<DeclStmt>(S)) {
+      for (const Decl *D : DS->getDeclGroup()) {
+        if (const VarDecl *VD = llvm::dyn_cast<VarDecl>(D)) {
+          const Expr *Init = VD->getInit();
----------------
steakhal wrote:
> RedDocMD wrote:
> > steakhal wrote:
> > > So you are trying to find the assignment, where the inner pointer is assigned to a variable.
> > > This visitor logic seems to be somewhat convoluted.
> > > 
> > > What you want to achieve is slightly similar to `FindLastStoreBRVisitor`. You should have a look at that.
> > That is what I had done before. @NoQ pointed out why this wouldn't work in a previous comment.
> Please elaborate on that.
> I'm not saying that an already existing visitor would perfectly fit your needs. I'm just curious why a //similar// logic would not work for you. You are trying to iterate over a bunch of decls and init exprs etc. And there is nothing similar to the visitor I mentioned.
Sorry. I should have written it out better.
> So you are trying to find the assignment, where the inner pointer is assigned to a variable.
Yes and no. I am indeed trying to find where the //first// assignment occurred, since re-assigning to the pointer obtained from `get()` doesn't give any information regarding regarding the smart pointer being null or not. So what this visitor does that it goes back to the original assignment to find out what SVal was bound to `a.get()`. The Environment doesn't have this info since it is garbage collected somewhere on the way. Also accessing this State allows me to check whether the SVal was null to begin with.
I don't think `FindLastStoreBRVisitor` does this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97183/new/

https://reviews.llvm.org/D97183



More information about the cfe-commits mailing list