<div dir="ltr">Hey all,<div><br></div><div><div>Suppose I'm working with the following C snippet:</div><div><br></div><div>void inc(int *num) {*num++;}</div><div>void dec(int *num) {*num--;}</div><div><br></div><div>void f(int var) {</div>
<div> inc(&var);</div><div> dec(&var);</div><div>}</div><div><br></div><div>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.</div>
<div><br></div><div>For example: if I use the following API</div><div><br></div><div>void MySimpleChecker::checkPostCall(const CallEvent &Call,</div><div> CheckerContext &C) const {</div>
<div> SymbolRef MyArg = Call.getArgSVal(0).getAsSymbol();</div><div>}</div><div><br></div><div>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.</div>
<div><br></div><div>What am I missing here? What concepts did I get wrong?</div><div><br></div><div>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.</div>
</div><div><br></div><div>Thanks in advance!</div><div><br></div><div>Best regards,</div><div><br></div><div>Ivan</div></div>