Search code examples
c++11abstract-syntax-treeclang++llvm-clanglibtooling

Exception during running custom clang Frontend tool on some input files


I have written a custom clang Frontend tool according to the following link. http://clang.llvm.org/docs/RAVFrontendAction.html

Now I am giving clang source code itself to my frontend tool for static analysis. My tool is throwing an exception for this test case https://llvm.org/svn/llvm-project/cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp

From the documentation of this test case, It is written for undefined behavior. And while running ClangTool on this test it throws stackoverflow exception even before the control comes in HandleTranslationUnit.

As clang can generate AST for the above test case, I assume the exception might be coming during compilation. Now the question is can't I continue visiting AST nodes for such files as I don't care about the semantics of input source files. I am only interested in static analysis.

Is this the expected behavior? Then how to traverse the generated AST and visit the nodes. I am really stuck at this moment and have no clue how to proceed. Would you please help me to fix this issue.

Thanks in advance!

Thanks, Hemant Bhagat


Solution

  • I found the answer. There is problem with system recursion depth. On Windows default recursion depth limit is 512. So in the case of test case mentioned in question, stack is getting overflowed even before reaching recursion limit. Hence decreasing the recursion depth limit to 27 avoided stack overflow exception.

    Similar is the case with template depth.