[cfe-dev] How can I get and manipulate the Store and Environment in the current ProgramState in Clang Static Analyzer?

Jordan Rose jordan_rose at apple.com
Thu Jul 11 17:31:50 PDT 2013


SVals are values; you can't change them. It'd be like saying x is 2, and now you want to change 2 into 3, when you really want to assign 3 to x.

What are you actually trying to do here?
Jordan


On Jul 11, 2013, at 3:58 , Arthur Yoo <phjy007 at gmail.com> wrote:

> 
> Jordan:
> 
> It's so kind of you to answer my questions. If I get a SVal variable, how can I modify its value? For an example, I have a SVal. With dump(), it shows '2 S32b'. I want to change its value to 3. So how can I do that? Thank you.
> 
> Arthur
> 
> 
> 2013/7/10 Jordan Rose <jordan_rose at apple.com>
> Hi, Arthur. The Store and Environment are not manipulated directly. Rather, you use the methods of ProgramState to access them.
> 
> ...and that said, checkers should hardly ever need to modify the Store and Environment. Most of the time, you should be storing your state in the generic data map (the set<> and get<> methods of ProgramState). Modifying the Environment arbitrarily can break invariants about what does and doesn't have a value. The Store is a little safer—performing simple bindings and providing default values is usually safe for checkers. Just be careful about types.
> 
> The keys in the environment are a tuple of the statement and the location context. The location context is what allows us to handle recursive functions without the callee's bindings stomping on the caller's. We don't have a great way to print a location context, so we just use the pointer value. (Perhaps a stack depth would be helpful?)
> 
> Hope that helps,
> Jordan.
> 
> P.S. I can't remember if we've suggested this to you already, but there are some reference materials at http://clang-analyzer.llvm.org/checker_dev_manual.html. In the first paragraph there's also a link to the talk Anna Zaks and I gave at last year's LLVM Developers' Meeting, which runs through how to build a simple checker and use the generic data map.
> 
> 
> On Jul 8, 2013, at 5:43 , Arthur Yoo <phjy007 at gmail.com> wrote:
> 
>> Hi all,
>> 
>> I want to get and manipulate the Store and Environment in the current ProgramState in checkPreStmt() and checkPostStmt(). How can I do that? 
>> 
>> What's more, I’ve dumped the ProgramState in my checker in checkPostStmt(). But I don’t know the meaning of addresses in the Expressions. What do those addresses mean? Thanks a lot. Any help will be greatly appreciated.
>> 
>> 
>> 
>> Best regards,
>> Arthur Yoo
>> 
>> _______________________________________________
>> 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/20130711/447b7d58/attachment.html>


More information about the cfe-dev mailing list