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

Alexander Droste alexander.ra.droste at googlemail.com
Thu Apr 16 08:00:55 PDT 2015


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.




More information about the cfe-dev mailing list