[cfe-dev] [StaticAnalyzer]: Cant get my checker to output

Anna Zaks ganna at apple.com
Wed Sep 28 11:19:10 PDT 2011


Hello,

Check if your checker is properly registered. You can use the following command to view the registered checkers:
$ clang -cc1 -analyzer-checker-help
Only some of them will get executed when scan-build is run (If you see your checker listed in scan-build output, it should be executed). 

Are there if statements in your test program? You would see the output only when an if statement is processed.

While developing/debugging a checker, you can use the following command (this will execute only the specified checker):
$ clang -cc1 -analyze -analyzer-checker=core.StackAddressEscape input.cpp

You can print debug messages with:
llvm::errs()<<"Hello";
llvm::outs()<<"Hello";

Cheers,
Anna.

On Sep 28, 2011, at 9:48 AM, funceval wrote:

> Hi,
> 
> How do I find out if my checker has run or not? There doesn't seem to be any option in scan-build that tells us which checkers were run. I tried printing to std::cout, std::cerr but nothing got printed. I tried generating a bug report but that didn't get generated either. But my checker does show up in the list of checkers when I run scan-build. I have even entered the details in Checkers.td. 
> 
> Here is what I have tried far:
> 
> namespace {
>           class ConstantConditionChecker : public Checker<check::PostStmt<IfStmt> >{
>               mutable llvm::OwningPtr<BuiltinBug> BT;
>           public:
>                   void checkPostStmt(const IfStmt *ifStmt, CheckerContext &C) const;
>           };
>   }
> 
>   void ConstantConditionChecker::checkPostStmt(const IfStmt *ifStmt, CheckerContext &C) const
>   {
>       ASTContext& astContext = C.getASTContext();
>       std::string sbuf;
>       llvm::raw_string_ostream Out(sbuf);
> 
>       ifStmt->getCond()->printPretty(Out, NULL, PrintingPolicy(astContext.getLangOptions()));
>       std::cerr << Out.str() << std::endl;
>       std::cout << "Hello\n" << std::endl;
>       std::cerr << "Hello cerr" << std::endl;
>       if (!BT)
>           BT.reset(new BuiltinBug(Out.str().c_str()));
>       BugReport* R = new BugReport(*BT, BT->getDescription(), C.getPredecessor());
>       R->addRange(ifStmt->getSourceRange());
>       C.EmitReport(R);
> 
>   }
> 
>   void ento::registerConstantConditionChecker(CheckerManager &mgr) {
>       mgr.registerChecker<ConstantConditionChecker>();
>   }
> 
> _______________________________________________
> 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/144d315e/attachment.html>


More information about the cfe-dev mailing list