[cfe-dev] Troubles tracking a function parameter with the static analyzer
Ivan Reche
ivan.reche at gmail.com
Mon May 12 20:09:12 PDT 2014
Hey all,
Suppose I'm working with the following C snippet:
void inc(int *num) {*num++;}
void dec(int *num) {*num--;}
void f(int var) {
inc(&var);
dec(&var);
}
By using a static analyzer, I want to be able to tell if the value of var
didn't change during the function's execution. I know I have to keep its
state on my own (that's the point of writing a Clang checker), but I'm
having troubles getting a unique reference of this variable.
For example: if I use the following API
void MySimpleChecker::checkPostCall(const CallEvent &Call,
CheckerContext &C) const {
SymbolRef MyArg = Call.getArgSVal(0).getAsSymbol();
}
I'd expect it to return a pointer to this symbol's representation in my
checker's context. However, I always get 0 into MyArg by using it this way.
This happens for both inc and dec functions in the pre and post callbacks.
What am I missing here? What concepts did I get wrong?
Note: I'm currently reading the Clang CFE Internals Manual and I've read
the excellent How to Write a Checker in 24 Hours material. I still couldn't
find my answer so far.
Thanks in advance!
Best regards,
Ivan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140513/8b7b1af3/attachment.html>
More information about the cfe-dev
mailing list