[cfe-dev] Traverse AST and save Stmt* pointers for later use

Aleksei Sidorin via cfe-dev cfe-dev at lists.llvm.org
Fri May 11 01:52:04 PDT 2018


Hello Igor,

There is too few information to say definitely what happens in your 
case. Could you share the code?
My wild guess is that you are trying to check the whole result after 
ASTContext storing all Stmts dies causing use-after-free.

11.05.2018 10:55, Иванов Игорь via cfe-dev пишет:
> Hello everyone!
>
> I am writing a tool that traverses ASTs of my project files, stores several  Stmt*  pointers, and then compares them as present here https://clang.llvm.org/doxygen/IdenticalExprChecker_8cpp_source.html#l00307 .
>
> I tried inheriting from  ast_matchers::MatchFinder::MatchCallback  and overriding its  void run(const MatchResult &match)  /  inheriting  RecursiveASTVisitor  and implementing  VisitFunctionDecl  to store pointers of interest into a container. However it seems that at some point during/after traversing those pointers invalidate - e.g. if I check body->getStmtClass() during run, it correctly shows CompoundStmt , but afterwards it turns into some other clearly wrong class like If or For.
>
> What are my options to solve this problem? I am aware that AST Matchers or Visitors might be a wrong tool in this case, so please don't hesitate to advise other means if those will suit me better.
>
> Best regards,
> Igor Ivanov
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


-- 
Best regards,
Aleksei Sidorin,
SRR, Samsung Electronics




More information about the cfe-dev mailing list