[cfe-dev] How to detect all return statements by Clang Libtooling?

조명진 happybrown at naver.com
Wed Feb 5 23:49:02 PST 2014


Hi all,

 

I’m trying to use clang libtooling for detecting all return statements.

 

I used the “VisitReturnStmt” function but sometimes it is not working as
follow case.

 

//target code

class ExampleFrontendAction : public ASTFrontendAction {

public:

    virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI, StringRef
file) {

        return new ExampleASTConsumer(&CI); // pass CI pointer to
ASTConsumer

    }

};

//target code end

 

//results

CXXMethodDecl 0x2468cb0 </project/llvm/Debug+Asserts/bin/a.cpp:107:5,
line:115:5> CreateASTConsumer 'int *(int &, int)'

|-ParmVarDecl 0x2468b60 <line:107:44, col:62> CI 'int &' invalid

|-ParmVarDecl 0x2468bd0 <col:66, col:76> file 'int' invalid

`-CompoundStmt 0x2469138 <col:82, line:115:5> invalid

 

As you can see, we cannot find any ReturnStmt. (It is included in
CompoundStmt. Also the CompoundStmt is a leaf statement.)

 

How can I detect this case? Please help me! 

 

Thanks in advance.

 

Additional Question.

Why does clang return “int *” instead of “ASTConsumer *” in the case of
CreateASTConsumer method when I use getReturnType() in VisitFunctionDecl()? 

 

Any ideas?

 

Brown.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140206/e1486fe2/attachment.html>


More information about the cfe-dev mailing list