[cfe-dev] [StaticAnalyzer]: Cant get my checker to output
Arjun Singri
arjunsingri at gmail.com
Wed Sep 28 22:51:46 PDT 2011
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:
namespace {
class ConstantConditionChecker : public
Checker<check::PostStmt<Stmt> >{
public:
void checkPostStmt(const Stmt *stmt, CheckerContext &C)
const;
};
}
void ConstantConditionChecker::checkPostStmt(const Stmt *stmt,
CheckerContext &C) const
{
ASTContext& astContext = C.getASTContext();
std::string sbuf;
llvm::raw_string_ostream Out(sbuf);
if (const IfStmt *ifStmt = dyn_cast<IfStmt>(stmt))
{
stmt->printPretty(Out, NULL,
PrintingPolicy(astContext.getLangOptions()));
llvm::errs()<< Out.str().c_str();
llvm::errs() << "Hello\n";
}
if (const WhileStmt *whileStmt = dyn_cast<WhileStmt>(stmt))
{
stmt->printPretty(Out, NULL,
PrintingPolicy(astContext.getLangOptions()));
llvm::errs() << Out.str().c_str();
llvm::errs() << "Hello2\n";
}
if (stmt->getStmtClass() == Stmt::IfStmtClass)
{
llvm::errs() << "StmtClass\n";
}
}
void ento::registerConstantConditionChecker(CheckerManager &mgr) {
mgr.registerChecker<ConstantConditionChecker>();
}
class
On Wed, Sep 28, 2011 at 9:03 PM, Arjun Singri <arjunsingri at gmail.com> wrote:
> 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.
>
> Here is the code I am trying to analyze:
>
> #include<stdio.h>
>
> int foo() { return 2; }
>
> int main(void)
> {
> int a = foo();
> int b = foo();
>
> scanf("%d", &a);
>
> a = a + b;
> if (a == 2)
> {
> a = 4;
> }
>
> printf("%d", a);
>
> return 0;
> }
>
>
>
>
> On Wed, Sep 28, 2011 at 7:54 PM, Jim Goodnow II <Jim at thegoodnows.net>wrote:
>
>> Hi Arjun,
>>
>> Do you have a short example of the code that you are analyzing. It is
>> possible that the static analyzer has determined that the if statement
>> is in a path that never gets executed. It should still be in the AST
>> though. You can use -ast-dump to look at the AST directly.
>>
>> - jim
>>
>> On 9/28/2011 7:40 PM, John McCall wrote:
>> > On Sep 28, 2011, at 7:34 PM, funceval wrote:
>> >> Not even constant folding and constant propagation?
>> > 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.
>> >
>> > John.
>> > _______________________________________________
>> > cfe-dev mailing list
>> > cfe-dev at cs.uiuc.edu
>> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>> >
>> >
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110928/c52c4763/attachment.html>
More information about the cfe-dev
mailing list