[cfe-dev] How to get global variables' SymbolRef?
Jordan Rose
jordan_rose at apple.com
Tue Nov 12 09:19:11 PST 2013
The first thing is that there are a couple of things wrong with your plan: global variables have regions, not symbols, and the state of memory is modeled by the Store, not the Environment. checkASTDecl is for syntactic checks, not path-sensitive ones, so of course the globals have no value.
What you actually need depends a lot on what sort of analysis you’re doing. If you’re trying to verify the initial values of global variables, you can use checkASTDecl and the normal constant-evaluation functions in the AST library. If you’re trying to check the state of all global variables at a particular time…that’s a bit harder, but I’m almost sure you don’t need it. (Why does your checker care about errno, for example?) So, what check are you trying to implement?
I also recommend you read through the Checker Developer Manual at http://clang-analyzer.llvm.org/checker_dev_manual.html, or watch the talk linked from there, for a firm grounding in the design of the analyzer and component classes.
Best,
Jordan
On Nov 11, 2013, at 22:58 , edward jiamu <edwardjiamu at gmail.com> wrote:
> 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.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131112/2c378c82/attachment.html>
More information about the cfe-dev
mailing list