From 7d64c9e3ec9988bc0f88cd847677174c3a974aad Mon Sep 17 00:00:00 2001 From: Ivan Donchevskii Date: Wed, 30 Jan 2019 09:07:45 +0100 Subject: [PATCH] Clang: Fix some issues with running indexer over Qt Creator - fix qDebug channels on Windows - fix the number of perameters in the sql statement - fix nullptr access - speed up preprocessor a little bit Change-Id: Ic9b32fbcc6b409c4064c4f522b94391cbff8654e Reviewed-by: Marco Bubke --- src/libs/clangsupport/commandlinebuilder.h | 2 +- src/libs/clangsupport/projectpartcontainer.h | 3 ++- .../clangpchmanagerbackendmain.cpp | 13 +++++++++++ .../source/collectbuilddependencyaction.h | 1 + .../clangrefactoringbackendmain.cpp | 13 +++++++++++ .../source/clangtool.h | 2 -- .../source/symbolstorage.h | 6 +++-- .../source/symbolsvisitorbase.h | 3 ++- .../builddependencycollector-test.cpp | 5 ----- .../unit/unittest/commandlinebuilder-test.cpp | 22 +++++++++---------- tests/unit/unittest/pchcreator-test.cpp | 4 ++-- tests/unit/unittest/symbolindexer-test.cpp | 16 +++++++------- 12 files changed, 57 insertions(+), 33 deletions(-) diff --git a/src/libs/clangsupport/commandlinebuilder.h b/src/libs/clangsupport/commandlinebuilder.h index df116197ab1..9b5bced9328 100644 --- a/src/libs/clangsupport/commandlinebuilder.h +++ b/src/libs/clangsupport/commandlinebuilder.h @@ -270,7 +270,7 @@ public: void addNoStdIncAndNoStdLibInc() { commandLine.emplace_back("-nostdinc"); - commandLine.emplace_back("-nostdlibinc"); + commandLine.emplace_back("-nostdinc++"); } public: diff --git a/src/libs/clangsupport/projectpartcontainer.h b/src/libs/clangsupport/projectpartcontainer.h index 41ae071961d..06065911372 100644 --- a/src/libs/clangsupport/projectpartcontainer.h +++ b/src/libs/clangsupport/projectpartcontainer.h @@ -161,5 +161,6 @@ public: using ProjectPartContainers = std::vector; -QDebug operator<<(QDebug debug, const ProjectPartContainer &container); +CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const ProjectPartContainer &container); + } // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp b/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp index 5c38a3d8413..c4e8e085ce2 100644 --- a/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp +++ b/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp @@ -55,6 +55,7 @@ #include #include #include +#include #include using namespace std::chrono_literals; @@ -214,8 +215,20 @@ struct Data // because we have a cycle dependency ClangBackEnd::CallDoInMainThreadAfterFinished::Yes}; }; +#ifdef Q_OS_WIN +static void messageOutput(QtMsgType type, const QMessageLogContext &, const QString &msg) +{ + std::wcout << msg.toStdWString() << std::endl; + if (type == QtFatalMsg) + abort(); +} +#endif + int main(int argc, char *argv[]) { +#ifdef Q_OS_WIN + qInstallMessageHandler(messageOutput); +#endif try { QCoreApplication::setOrganizationName(QStringLiteral("QtProject")); QCoreApplication::setOrganizationDomain(QStringLiteral("qt-project.org")); diff --git a/src/tools/clangpchmanagerbackend/source/collectbuilddependencyaction.h b/src/tools/clangpchmanagerbackend/source/collectbuilddependencyaction.h index ff861f174f0..03d27f9b21e 100644 --- a/src/tools/clangpchmanagerbackend/source/collectbuilddependencyaction.h +++ b/src/tools/clangpchmanagerbackend/source/collectbuilddependencyaction.h @@ -58,6 +58,7 @@ public: auto &preprocessor = compilerInstance.getPreprocessor(); preprocessor.SetSuppressIncludeNotFoundError(true); + preprocessor.SetMacroExpansionOnlyInDirectives(); auto macroPreprocessorCallbacks = new CollectBuildDependencyPreprocessorCallbacks( m_buildDependency, diff --git a/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp b/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp index 0d483bbeaf1..23a127c17f2 100644 --- a/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp +++ b/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp @@ -39,6 +39,7 @@ #include #include +#include using namespace std::chrono_literals; @@ -97,8 +98,20 @@ struct Data // because we have a cycle dependency SymbolIndexing symbolIndexing{database, filePathCache, generatedFiles, [&] (int progress, int total) { clangCodeModelServer.setProgress(progress, total); }}; }; +#ifdef Q_OS_WIN +static void messageOutput(QtMsgType type, const QMessageLogContext &, const QString &msg) +{ + std::wcout << msg.toStdWString() << std::endl; + if (type == QtFatalMsg) + abort(); +} +#endif + int main(int argc, char *argv[]) { +#ifdef Q_OS_WIN + qInstallMessageHandler(messageOutput); +#endif try { QCoreApplication::setOrganizationName(QStringLiteral("QtProject")); QCoreApplication::setOrganizationDomain(QStringLiteral("qt-project.org")); diff --git a/src/tools/clangrefactoringbackend/source/clangtool.h b/src/tools/clangrefactoringbackend/source/clangtool.h index b9d366859e3..8b4e47df682 100644 --- a/src/tools/clangrefactoringbackend/source/clangtool.h +++ b/src/tools/clangrefactoringbackend/source/clangtool.h @@ -95,8 +95,6 @@ public: bool isClean() const; - - private: RefactoringCompilationDatabase m_compilationDatabase; std::vector m_fileContents; diff --git a/src/tools/clangrefactoringbackend/source/symbolstorage.h b/src/tools/clangrefactoringbackend/source/symbolstorage.h index f2993f9a43c..f1fdbc7c02e 100644 --- a/src/tools/clangrefactoringbackend/source/symbolstorage.h +++ b/src/tools/clangrefactoringbackend/source/symbolstorage.h @@ -341,12 +341,14 @@ public: m_database}; mutable ReadStatement m_getProjectPartArtefactsBySourceId{ "SELECT toolChainArguments, compilerMacros, systemIncludeSearchPaths, " - "projectIncludeSearchPaths, projectPartId FROM projectParts WHERE projectPartId = (SELECT " + "projectIncludeSearchPaths, projectPartId, language, languageVersion, languageExtension " + "FROM projectParts WHERE projectPartId = (SELECT " "projectPartId FROM projectPartsSources WHERE sourceId = ?)", m_database}; mutable ReadStatement m_getProjectPartArtefactsByProjectPartName{ "SELECT toolChainArguments, compilerMacros, systemIncludeSearchPaths, " - "projectIncludeSearchPaths, projectPartId FROM projectParts WHERE projectPartName = ?", + "projectIncludeSearchPaths, projectPartId, language, languageVersion, languageExtension " + "FROM projectParts WHERE projectPartName = ?", m_database}; mutable ReadStatement m_getPrecompiledHeader{ "SELECT projectPchPath, projectPchBuildTime FROM precompiledHeaders WHERE projectPartId = ?", diff --git a/src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h b/src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h index c833f73afbe..ff2142f40e2 100644 --- a/src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h +++ b/src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h @@ -68,7 +68,8 @@ public: bool isAlreadyParsed(clang::FileID fileId) { const clang::FileEntry *fileEntry = m_sourceManager->getFileEntryForID(fileId); - + if (!fileEntry) + return false; return m_sourcesManager.alreadyParsed(filePathId(fileEntry), fileEntry->getModificationTime()); } diff --git a/tests/unit/unittest/builddependencycollector-test.cpp b/tests/unit/unittest/builddependencycollector-test.cpp index 4631a883766..3c9ea84d32b 100644 --- a/tests/unit/unittest/builddependencycollector-test.cpp +++ b/tests/unit/unittest/builddependencycollector-test.cpp @@ -435,9 +435,7 @@ TEST_F(BuildDependencyCollector, CollectUsedMacrosWithExternalDefine) ElementsAre(Eq(UsedMacro{"DEFINED", fileId}), Eq(UsedMacro{"IF_DEFINE", fileId}), Eq(UsedMacro{"__clang__", fileId}), - Eq(UsedMacro{"CLASS_EXPORT", fileId}), Eq(UsedMacro{"IF_NOT_DEFINE", fileId}), - Eq(UsedMacro{"MACRO_EXPANSION", fileId}), Eq(UsedMacro{"COMPILER_ARGUMENT", fileId}))); } @@ -452,9 +450,7 @@ TEST_F(BuildDependencyCollector, CollectUsedMacrosWithoutExternalDefine) ElementsAre(Eq(UsedMacro{"DEFINED", fileId}), Eq(UsedMacro{"IF_DEFINE", fileId}), Eq(UsedMacro{"__clang__", fileId}), - Eq(UsedMacro{"CLASS_EXPORT", fileId}), Eq(UsedMacro{"IF_NOT_DEFINE", fileId}), - Eq(UsedMacro{"MACRO_EXPANSION", fileId}), Eq(UsedMacro{"COMPILER_ARGUMENT", fileId}))); } @@ -639,7 +635,6 @@ TEST_F(BuildDependencyCollector, Create) SourceType::TopProjectInclude))), Field(&BuildDependency::usedMacros, UnorderedElementsAre( - UsedMacro{"DEFINE", id(TESTDATA_DIR "/builddependencycollector/project/macros.h")}, UsedMacro{"IFDEF", id(TESTDATA_DIR "/builddependencycollector/project/macros.h")}, UsedMacro{"DEFINED", id(TESTDATA_DIR "/builddependencycollector/project/macros.h")})), diff --git a/tests/unit/unittest/commandlinebuilder-test.cpp b/tests/unit/unittest/commandlinebuilder-test.cpp index c3b60df3694..c3dad70de3c 100644 --- a/tests/unit/unittest/commandlinebuilder-test.cpp +++ b/tests/unit/unittest/commandlinebuilder-test.cpp @@ -136,7 +136,7 @@ TYPED_TEST(CommandLineBuilder, CTask) ASSERT_THAT( builder.commandLine, - ElementsAre("clang", "-x", "c-header", "-std=c11", "-nostdinc", "-nostdlibinc", "/source/file.c")); + ElementsAre("clang", "-x", "c-header", "-std=c11", "-nostdinc", "-nostdinc++", "/source/file.c")); } TYPED_TEST(CommandLineBuilder, ObjectiveCTask) @@ -153,7 +153,7 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCTask) "objective-c-header", "-std=c11", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "/source/file.c")); } @@ -170,7 +170,7 @@ TYPED_TEST(CommandLineBuilder, CppTask) "c++-header", "-std=c++98", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "/source/file.cpp")); } @@ -188,7 +188,7 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCppTask) "objective-c++-header", "-std=c++98", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "/source/file.cpp")); } @@ -420,7 +420,7 @@ TYPED_TEST(CommandLineBuilder, IncludesOrder) "c++-header", "-std=c++11", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "-I", "/include/foo", "-I", @@ -441,7 +441,7 @@ TYPED_TEST(CommandLineBuilder, EmptySourceFile) Builder builder{this->emptyProjectInfo, {}, {}}; ASSERT_THAT(builder.commandLine, - ElementsAre("clang++", "-x", "c++-header", "-std=c++98", "-nostdinc", "-nostdlibinc")); + ElementsAre("clang++", "-x", "c++-header", "-std=c++98", "-nostdinc", "-nostdinc++")); } TYPED_TEST(CommandLineBuilder, SourceFile) @@ -454,7 +454,7 @@ TYPED_TEST(CommandLineBuilder, SourceFile) "c++-header", "-std=c++98", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "/source/file.cpp")); } @@ -469,7 +469,7 @@ TYPED_TEST(CommandLineBuilder, EmptyOutputFile) "c++-header", "-std=c++98", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "/source/file.cpp")); } @@ -483,7 +483,7 @@ TYPED_TEST(CommandLineBuilder, OutputFile) "c++-header", "-std=c++98", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "-o", "/output/file.o", "/source/file.cpp")); @@ -499,7 +499,7 @@ TYPED_TEST(CommandLineBuilder, IncludePchPath) "c++-header", "-std=c++98", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "-Xclang", "-include-pch", "-Xclang", @@ -521,7 +521,7 @@ TYPED_TEST(CommandLineBuilder, CompilerMacros) "c++-header", "-std=c++98", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "-DER=2", "-DYI=1")); } diff --git a/tests/unit/unittest/pchcreator-test.cpp b/tests/unit/unittest/pchcreator-test.cpp index 0da712d9836..26ca9965c2f 100644 --- a/tests/unit/unittest/pchcreator-test.cpp +++ b/tests/unit/unittest/pchcreator-test.cpp @@ -157,7 +157,7 @@ TEST_F(PchCreator, CreateProjectPartClangCompilerArguments) "c++-header", "-std=c++98", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", @@ -183,7 +183,7 @@ TEST_F(PchCreator, CreateProjectPartClangCompilerArgumentsWithSystemPch) "c++-header", "-std=c++98", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", diff --git a/tests/unit/unittest/symbolindexer-test.cpp b/tests/unit/unittest/symbolindexer-test.cpp index 4f112d45298..104c17b11b3 100644 --- a/tests/unit/unittest/symbolindexer-test.cpp +++ b/tests/unit/unittest/symbolindexer-test.cpp @@ -269,7 +269,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesInCollector) "c++-header", "-std=c++14", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "-DBAR=1", "-DFOO=1", "-I", @@ -299,7 +299,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithPrecompiledHeaderInColl "c++-header", "-std=c++14", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "-DBAR=1", "-DFOO=1", "-I", @@ -332,7 +332,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithoutPrecompiledHeaderInC "c++-header", "-std=c++14", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "-DBAR=1", "-DFOO=1", "-I", @@ -512,7 +512,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithoutProjectPartArtifact) "c++-header", "-std=c++14", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "-DBAR=1", "-DFOO=1", "-I", @@ -564,7 +564,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithProjectPartArtifact) "c++-header", "-std=c++14", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "-DBAR=1", "-DFOO=1", "-I", @@ -620,7 +620,7 @@ TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrder) "c++-header", "-std=c++14", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "-DBAR=1", "-DFOO=1", "-I", @@ -682,7 +682,7 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsUsingPrecompiledHeader) "c++-header", "-std=c++14", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "-DBAR=1", "-DFOO=1", "-I", @@ -717,7 +717,7 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsNotUsingPrecompiledHeaderIfItNotExists) "c++-header", "-std=c++14", "-nostdinc", - "-nostdlibinc", + "-nostdinc++", "-DBAR=1", "-DFOO=1", "-I",