[cfe-dev] Interesting error during generate the call graph via clang libtooling

yin liu via cfe-dev cfe-dev at lists.llvm.org
Wed Jul 19 15:01:45 PDT 2017


Hi,

I found an issue during generate the call graph by using
clang::CallGraph addToCallGraph().

I build a ClangTool that matches the specific decl in the source code,
then, in this clang tool, I can use the clang::CallGraph
addToCallGraph() to generate the call graph. However, the interesting
thing is, I cannot use the same way outside the ClangTool. That means
if I store the matched decl into a global variable and generate the
clang::CallGraph outside the ClangTool (e.g., in the main function).
It give me several errors attached below.

My question is ... why it happens?

Here is the code in main.cpp:

// global variable storing the matched function decl
clang::FunctionDecl *testFnDecl;

// clang tool for getting the decl and put it to a global variable testFnDecl
ClangTool getFnTool (OptionsParser.getCompilations(),
            OptionsParser.getSourcePathList());
GetFnCallback getFnCallback;
ast_matchers::MatchFinder annotatedFnFinder;
FnFinder.addMatcher(functionDecl().bind("Decls"), &getFnCallback);
getFnTool.run(newFrontendActionFactory(&FnFinder).get());

//generate the call graph
clang::CallGraph testCG;
testCG.addToCallGraph(testFnDecl);
testCG.addToCallGraph(testGlobalFnDecl);
testCG.dump();

Here is the error:
 ./transformer(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamE+0x33)[0xc91abf]
 ./transformer[0xc91b52]//
./transformer(_ZN4llvm3sys17RunSignalHandlersEv+0x99)[0xc8fe0d]
 ./transformer[0xc91334]//
/lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7f9334dec390]
 ./transformer[0xb9be2c]//   ./transformer[0xb9fa72]//
./transformer(_ZN5clang19RecursiveASTVisitorINS_9CallGraphEE15TraverseTypeLocENS_7TypeLocE+0x48)[0xbcee94]//
  ./transformer(_ZN5clang19RecursiveASTVisitorINS_9CallGraphEE24TraverseDeclaratorHelperEPNS_14DeclaratorDeclE+0xe9)[0xbd2bfd]//
  ./transformer(_ZN5clang19RecursiveASTVisitorINS_9CallGraphEE17TraverseVarHelperEPNS_7VarDeclE+0x2c)[0xbd3794]//
  ./transformer(_ZN5clang19RecursiveASTVisitorINS_9CallGraphEE19TraverseParmVarDeclEPNS_11ParmVarDeclE+0x81)[0xbc31b7]//
  ./transformer(_ZN5clang19RecursiveASTVisitorINS_9CallGraphEE12TraverseDeclEPNS_4DeclE+0xe57)[0xbb4155]//
  ./transformer(_ZN5clang19RecursiveASTVisitorINS_9CallGraphEE28TraverseFunctionProtoTypeLocENS_20FunctionProtoTypeLocE+0x1ad)[0xbe5aff]//
  ./transformer(_ZN5clang19RecursiveASTVisitorINS_9CallGraphEE15TraverseTypeLocENS_7TypeLocE+0x458)[0xbcf2a4]//
  ./transformer(_ZN5clang19RecursiveASTVisitorINS_9CallGraphEE22TraverseFunctionHelperEPNS_12FunctionDeclE+0x224)[0xbd3054]//
  ./transformer(_ZN5clang19RecursiveASTVisitorINS_9CallGraphEE20TraverseFunctionDeclEPNS_12FunctionDeclE+0x7a)[0xbc2280]//
  ./transformer(_ZN5clang19RecursiveASTVisitorINS_9CallGraphEE12TraverseDeclEPNS_4DeclE+0xbcf)[0xbb3ecd]//
  ./transformer(_ZN5clang9CallGraph14addToCallGraphEPNS_4DeclE+0x35)[0xbaa803]//
  ./transformer(_ZN20GetFunctionCallGraph17generateCallGraphERSt5dequeIPN5clang4DeclESaIS3_EE+0x15c)[0xb962fe]//
  ./transformer(main+0x4df)[0xb995c0]//
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f9333f76830]//
  ./transformer(_start+0x29)[0xb92f59]//   Segmentation fault (core
dumped)


Thanks in advance!
yl



More information about the cfe-dev mailing list