How can I get the analysis information of UnaryOperator in Clang Static Analyzer

Hi all,

It seems that the Clang Static Analyzer may miss the analysis information of UnaryOperator. For example:

void func(int s) {

s++;

++s;

}

The example may be quite ridiculous…

My checker contains a method: void checkPostStmt(const Stmt *DS, CheckerContext &C).

I thought that it can capture any kind of Stmt. Since UnaryOperator is a subclass of Expr and Expr is a subclass of Stmt, I thought my checker can give me the analysis information of “s++” and “++s”. However, it returned nothing.

What’ more, I have tried to add another checkPostStmt() method in my checker. The declaration

of this method is void checkPostStmt(const UnaryOperator *Op, CheckerContext &C). The result is same with the previous one, it returned nothing.

In fact, I want to use Clang Static Analyzer to capture all kinds of UnaryOperator, including ‘s++/++s/s–/–’(IncrementOp/DecrementOp). *p(pointer dereference) and so on. So how can I get the analysis information of UnaryOperator in Clang Static Analyzer?

Thanks a lot.

Hi, Arthur. Looks like we’re forgetting in Core to give checkers a chance for some of the unary operators. I’ll see if I can get to that soon; alternately, patches welcome!

Jordan

Fixed in r191532.

Jordan

Hi Jordan,

Thank you very much! :slight_smile: