[cfe-dev] how to track a stack var with static analyzer

Anna Zaks ganna at apple.com
Thu Apr 16 16:43:48 PDT 2015


> On Apr 16, 2015, at 8:00 AM, Alexander Droste <alexander.ra.droste at googlemail.com> wrote:
> 
> Hi everyone,
> 
> I'm trying to track a stack variable using the static analyzer
> by getting a symbol from function args.
> 
> In checkPostCall I do:
> 
> if (callEvent.getCalleeIdentifier() == IdentInfoTrackMem) {
>    // ...
>    auto s = callEvent.getArgSVal(0).getAsSymbol();
>    if (s == nullptr) {
>        std::cout << "nullptr" << std::endl;
>    }
> }
> 
> // this is function used to track the var
> void trackMem(int *i) {
>    *i = 0;
>    printf("%i\n", *i);
> }
> 
> 
> The strange thing is that it workes fine when the variable passed to
> trackMem is previously allocated with malloc. But when passing
> a pointer to a stack variable to trackMem callEvent.getArgSVal(0).getAsSymbol() always evaluates to nullptr.

The address of a stack variable is not a symbol. Take a look at this section of the Checker Developer Manual and examine the SVal that represents the 0-th argument.

http://clang-analyzer.llvm.org/checker_dev_manual.html#values <http://clang-analyzer.llvm.org/checker_dev_manual.html#values>

> 
> _______________________________________________
> 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/20150416/ae95d4fd/attachment.html>


More information about the cfe-dev mailing list