Ok I just verified that checkPostStmt is never executed for IfStmt. I changed the target type to "Stmt" and then tried to cast each Stmt to IfStmt. The dynamic cast was never successful. Tried using Stmt::getStmtClass() as well. I tried to prove this by printing out the run-time type by using typeid. But I got a compilation error saying I cannot use typeid with -fno-rtti. I did not know how to get around that. I don't know what I am missing. You can try it out by using the following:<div>
<br></div><div><div><div>namespace {</div><div> class ConstantConditionChecker : public Checker<check::PostStmt<Stmt> >{</div><div> public:</div><div> void checkPostStmt(const Stmt *stmt, CheckerContext &C) const;</div>
<div> };</div><div> }</div><div><br></div><div> void ConstantConditionChecker::checkPostStmt(const Stmt *stmt, CheckerContext &C) const</div><div> {</div><div> ASTContext& astContext = C.getASTContext();</div>
<div> std::string sbuf;</div><div> llvm::raw_string_ostream Out(sbuf);</div><div><br></div><div> if (const IfStmt *ifStmt = dyn_cast<IfStmt>(stmt))</div><div> {</div><div> stmt->printPretty(Out, NULL, PrintingPolicy(astContext.getLangOptions()));</div>
<div> llvm::errs()<< Out.str().c_str();</div><div> llvm::errs() << "Hello\n";</div><div> }</div><div><br></div><div> if (const WhileStmt *whileStmt = dyn_cast<WhileStmt>(stmt))</div>
<div> {</div><div> stmt->printPretty(Out, NULL, PrintingPolicy(astContext.getLangOptions()));</div><div> llvm::errs() << Out.str().c_str();</div><div> llvm::errs() << "Hello2\n";</div>
<div> }</div><div><br></div><div> if (stmt->getStmtClass() == Stmt::IfStmtClass)</div><div> {</div><div> llvm::errs() << "StmtClass\n";</div><div> }</div><div> }</div><div>
<br></div><div> void ento::registerConstantConditionChecker(CheckerManager &mgr) {</div><div> mgr.registerChecker<ConstantConditionChecker>();</div><div> }</div></div><div><br></div><div><br></div><div>class <br>
<br>
<div class="gmail_quote">On Wed, Sep 28, 2011 at 9:03 PM, Arjun Singri <span dir="ltr"><<a href="mailto:arjunsingri@gmail.com" target="_blank">arjunsingri@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>My checker was able to output (the debug messages show up) when I changed the IfStmt to BinaryOperator. So my checker has been registered correctly. It is not able to deal with IfStmt for some reason.</div><div><br>
</div>
Here is the code I am trying to analyze:<div><br></div><div><div>#include<stdio.h></div><div><br></div><div> int foo() { return 2; }</div><div><br></div><div> int main(void)</div><div> {</div><div> int a = foo();</div>
<div> int b = foo();</div><div><br></div><div> scanf("%d", &a);</div><div><br></div><div> a = a + b;</div><div> if (a == 2)</div><div> {</div><div> a = 4;</div><div> }</div>
<div><br></div><div> printf("%d", a);</div><div><br></div><div> return 0;</div><div><div></div><div><div> }</div><div><br></div><div><br></div><div><br></div><br><div class="gmail_quote">On Wed, Sep 28, 2011 at 7:54 PM, Jim Goodnow II <span dir="ltr"><<a href="mailto:Jim@thegoodnows.net" target="_blank">Jim@thegoodnows.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Arjun,<br>
<br>
Do you have a short example of the code that you are analyzing. It is<br>
possible that the static analyzer has determined that the if statement<br>
is in a path that never gets executed. It should still be in the AST<br>
though. You can use -ast-dump to look at the AST directly.<br>
<font color="#888888"><br>
- jim<br>
</font><div><div></div><div><br>
On 9/28/2011 7:40 PM, John McCall wrote:<br>
> On Sep 28, 2011, at 7:34 PM, funceval wrote:<br>
>> Not even constant folding and constant propagation?<br>
> Correct. A few places in the AST, like array dimensions, do compute and store the value of a constant expression, but only in unevaluated contexts, and the original source information is never thrown away.<br>
><br>
> John.<br>
</div></div><div><div></div><div>> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
><br>
><br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</div></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div>
</div>