[cfe-dev] How to detect all return statements by Clang Libtooling?
Manuel Klimek
klimek at google.com
Thu Feb 6 07:16:53 PST 2014
On Thu, Feb 6, 2014 at 8:49 AM, 조명진 <happybrown at naver.com> wrote:
> 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()?
>
My guess is that the headers are not correctly found; are you sure you're
using a compilation database that works?
>
>
> Any ideas?
>
>
>
> Brown.
>
> _______________________________________________
> 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/20140206/d1cac5ba/attachment.html>
More information about the cfe-dev
mailing list