[cfe-dev] How to get global variables' SymbolRef?

edward jiamu edwardjiamu at gmail.com
Mon Nov 11 22:58:22 PST 2013


Hi:
    I want to record all the global variables' SymbolRef for analysis. Try
the following ways, but failed.

   1) void check::checkPreStmt(const DeclStmt *DS, CheckerContext &C) const;
       only contains the local variables of the analysed function

   2) void check::checkASTDecl(const VarDecl *TU, AnalysisManager& mgr,
                    BugReporter &BR) const
      contains the global variables, but no CheckerContext info. so can not
convert it to SVal as usual:

      ProgramStateRef state = C.getState();
      SVal sv = state->getSVal(...);
      SymbolRef Sym = sv.getAsSymbol();

   3) depends on "state", how to get the "state" corresponding to the global
variables?
    Environment env = state->getEnvironment();
    for(Environment::iterator it = env.begin(); it != env.end(); ++it)
    {
        SVal sv = it->second;
        //...
    }

    is there correct way?

Best Regards.

Jiamu      



--
View this message in context: http://clang-developers.42468.n3.nabble.com/How-to-get-global-variables-SymbolRef-tp4035939.html
Sent from the Clang Developers mailing list archive at Nabble.com.



More information about the cfe-dev mailing list