[cfe-dev] Clang checker: 'beginning of function' hook?

Aemon Cannon aemoncannon at gmail.com
Wed Sep 4 04:43:53 PDT 2013


Gábor,

Thanks for the helpful suggestions. Your suspicion that checkPreCall is not
invoked for the entry function was correct. My current solution looks like
this:

void Checker::checkPostStmt(const Expr* S, CheckerContext &C) const {
  if (const DeclRefExpr* expr = dyn_cast<DeclRefExpr>(S->IgnoreImplicit()))
{
    if (const ParmVarDecl* param = dyn_cast<ParmVarDecl>(expr->getDecl())) {
      const SymbolRef sym = C.getSVal(S).getAsSymbol();
      if (!sym) return;
      ProgramStateRef State = C.getState();
      const MyState* arg_state = State->get<MyMap>(sym);
      if (arg_state) return;  // Only interested in first encounter
      ......
    }
  }
}

For some reason it did not work to register for PostStmt<DeclRefExpr>. I
believe the checker does not descend into ImplicitCast expressions.... so I
did that part manually. A bit of a hack, but it gets the job done, and it
has the lazy-initialized quality that you mentioned.

On a somewhat related note, I noticed that unused function parameters are
never reaped by the DeadSymbols callback. I'm considering doing my own
special handling for these, as I need to know when a parameter is 'leaked'
for my purposes. Any ideas there?

Best and thanks again,
Aemon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130904/22505c40/attachment.html>


More information about the cfe-dev mailing list