From 02b8dea10813606db4a013799a3e354368d0280f Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Wed, 30 Sep 2020 21:30:35 +0200 Subject: issue #8066: Doxygen crashes in ClangTUParser --- src/clangparser.cpp | 5 +++-- src/doxygen.cpp | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/clangparser.cpp b/src/clangparser.cpp index 1ac9138..1a91b8f 100644 --- a/src/clangparser.cpp +++ b/src/clangparser.cpp @@ -129,7 +129,7 @@ class ClangTUParser::Private std::vector ufs; std::vector cursors; std::unordered_map fileMapping; - CXTranslationUnit tu; + CXTranslationUnit tu = 0; CXToken *tokens = 0; uint numTokens = 0; StringVector filesInSameTU; @@ -858,7 +858,7 @@ class ClangParser::Private QCString clangCompileDatabase = Config_getString(CLANG_DATABASE_PATH); // load a clang compilation database (https://clang.llvm.org/docs/JSONCompilationDatabase.html) db = clang::tooling::CompilationDatabase::loadFromDirectory(clangCompileDatabase.data(), error); - if (clangCompileDatabase!="0" && db==nullptr) + if (!clangCompileDatabase.isEmpty() && clangCompileDatabase!="0" && db==nullptr) { // user specified a path, but DB file was not found err("%s using clang compilation database path of: \"%s\"\n", error.c_str(), @@ -884,6 +884,7 @@ ClangParser::~ClangParser() std::unique_ptr ClangParser::createTUParser(const FileDef *fd) const { + //printf("ClangParser::createTUParser()\n"); return std::make_unique(*this,fd); } diff --git a/src/doxygen.cpp b/src/doxygen.cpp index d442857..b4a2932 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -7507,7 +7507,11 @@ static void generateFileSources() { for (const auto &fd : *fn) { - if (fd->isSource() && !fd->isReference()) + if (fd->isSource() && !fd->isReference() && + ((fd->generateSourceFile() && !g_useOutputTemplate) || + (!fd->isReference() && Doxygen::parseSourcesNeeded) + ) + ) { auto clangParser = ClangParser::instance()->createTUParser(fd.get()); if (fd->generateSourceFile() && !g_useOutputTemplate) // sources need to be shown in the output @@ -7565,9 +7569,9 @@ static void generateFileSources() { if (processedFiles.find(fd->absFilePath().str())==processedFiles.end()) // not yet processed { - auto clangParser = ClangParser::instance()->createTUParser(fd.get()); if (fd->generateSourceFile() && !Htags::useHtags && !g_useOutputTemplate) // sources need to be shown in the output { + auto clangParser = ClangParser::instance()->createTUParser(fd.get()); msg("Generating code for file %s...\n",fd->docName().data()); clangParser->parse(); fd->writeSourceHeader(*g_outputList); @@ -7577,6 +7581,7 @@ static void generateFileSources() else if (!fd->isReference() && Doxygen::parseSourcesNeeded) // we needed to parse the sources even if we do not show them { + auto clangParser = ClangParser::instance()->createTUParser(fd.get()); msg("Parsing code for file %s...\n",fd->docName().data()); clangParser->parse(); fd->writeSourceHeader(*g_outputList); -- cgit v0.12