diff --git a/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp b/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp index 8fb8775194d3d76b9234e346b6aa922072c5f8bb..ad6363bc0e6be82109b68bec05096f20d4c41bfe 100644 --- a/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp +++ b/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp @@ -161,7 +161,8 @@ static void prependTargetTripleIfNotIncludedAndNotEmpty(QStringList *arguments, } // Removes (1) inputFile (2) -o . -QStringList inputAndOutputArgumentsRemoved(const QString &inputFile, const QStringList &arguments) +QStringList inputAndOutputArgumentsRemoved(const QString &inputFile, const QStringList &arguments, + bool isMsvc) { QStringList newArguments; @@ -173,6 +174,9 @@ QStringList inputAndOutputArgumentsRemoved(const QString &inputFile, const QStri } else if (argument == QLatin1String("-o")) { skip = true; continue; + } else if (isMsvc && argument == QLatin1String("-target")) { + skip = true; + continue; } else if (QDir::fromNativeSeparators(argument) == inputFile) { continue; // TODO: Let it in? } @@ -233,11 +237,23 @@ public: ClangStaticAnalyzerOptionsBuilder(const CppTools::ProjectPart &projectPart) : CompilerOptionsBuilder(projectPart) - , m_isMsvcToolchain(m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) + , m_isMsvcToolchain(m_projectPart.toolchainType + == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) + , m_isMinGWToolchain(m_projectPart.toolchainType + == ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID) { } public: + bool excludeHeaderPath(const QString &headerPath) const override + { + if (CompilerOptionsBuilder::excludeHeaderPath(headerPath)) + return true; + if (m_isMinGWToolchain && headerPath.contains(m_projectPart.toolChainTargetTriple)) + return true; + return false; + } + void undefineClangVersionMacrosForMsvc() { if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) { @@ -260,7 +276,7 @@ private: // For MSVC toolchains we use clang-cl.exe, so there is nothing to do here since // 1) clang-cl.exe does not understand the "-triple" option // 2) clang-cl.exe already hardcodes the right triple value (even if built with mingw) - if (m_projectPart.toolchainType != ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) + if (!m_isMsvcToolchain) CompilerOptionsBuilder::addTargetTriple(); } @@ -317,6 +333,7 @@ private: private: bool m_isMsvcToolchain; + bool m_isMinGWToolchain; }; static QStringList createMsCompatibilityVersionOption(const ProjectPart &projectPart) @@ -364,9 +381,12 @@ static QStringList tweakedArguments(const ProjectPart &projectPart, const QStringList &arguments, const QString &targetTriple) { - QStringList newArguments = inputAndOutputArgumentsRemoved(filePath, arguments); + const bool isMsvc = projectPart.toolchainType + == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID; + QStringList newArguments = inputAndOutputArgumentsRemoved(filePath, arguments, isMsvc); prependWordWidthArgumentIfNotIncluded(&newArguments, projectPart.toolChainWordWidth); - prependTargetTripleIfNotIncludedAndNotEmpty(&newArguments, targetTriple); + if (!isMsvc) + prependTargetTripleIfNotIncludedAndNotEmpty(&newArguments, targetTriple); newArguments.append(createHeaderPathsOptionsForClangOnMac(projectPart)); newArguments.append(createMsCompatibilityVersionOption(projectPart)); newArguments.append(createOptionsToUndefineClangVersionMacrosForMsvc(projectPart)); diff --git a/src/plugins/clangstaticanalyzer/clangstaticanalyzerunittests.cpp b/src/plugins/clangstaticanalyzer/clangstaticanalyzerunittests.cpp index c69855ecd28a58dfd1d5a4f31b746ebb4d208ffd..2ab8c18d9ba9d7279f1a61dafde697da1c96efaa 100644 --- a/src/plugins/clangstaticanalyzer/clangstaticanalyzerunittests.cpp +++ b/src/plugins/clangstaticanalyzer/clangstaticanalyzerunittests.cpp @@ -75,6 +75,13 @@ void ClangStaticAnalyzerUnitTests::testProject() { QFETCH(QString, projectFilePath); QFETCH(int, expectedDiagCount); + if (projectFilePath.contains("mingw")) { + const ToolChain * const toolchain + = ToolChainKitInformation::toolChain(KitManager::kits().first(), + Constants::CXX_LANGUAGE_ID); + if (toolchain->typeId() != ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID) + QSKIP("This test is mingw specific, does not run for other toolchais"); + } CppTools::Tests::ProjectOpenerAndCloser projectManager; const CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true); @@ -107,6 +114,9 @@ void ClangStaticAnalyzerUnitTests::testProject_data() addTestRow("qt-essential-includes/qt-essential-includes.qbs", 0); addTestRow("qt-essential-includes/qt-essential-includes.pro", 0); + + addTestRow("mingw-includes/mingw-includes.qbs", 0); + addTestRow("mingw-includes/mingw-includes.pro", 0); } void ClangStaticAnalyzerUnitTests::addTestRow(const QByteArray &relativeFilePath, diff --git a/src/plugins/clangstaticanalyzer/unit-tests/mingw-includes/main.cpp b/src/plugins/clangstaticanalyzer/unit-tests/mingw-includes/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fc104e426d5daa6b7a0503b6f7dc0bf80581e924 --- /dev/null +++ b/src/plugins/clangstaticanalyzer/unit-tests/mingw-includes/main.cpp @@ -0,0 +1,7 @@ +#include +#include "intrin.h" + +int main(int argc, char *argv[]) +{ + return 0; +} diff --git a/src/plugins/clangstaticanalyzer/unit-tests/mingw-includes/mingw-includes.pro b/src/plugins/clangstaticanalyzer/unit-tests/mingw-includes/mingw-includes.pro new file mode 100644 index 0000000000000000000000000000000000000000..c5faffece4c5306454009ef83727146e2442b80e --- /dev/null +++ b/src/plugins/clangstaticanalyzer/unit-tests/mingw-includes/mingw-includes.pro @@ -0,0 +1,3 @@ +CONFIG -= QT + +SOURCES += main.cpp diff --git a/src/plugins/clangstaticanalyzer/unit-tests/mingw-includes/mingw-includes.qbs b/src/plugins/clangstaticanalyzer/unit-tests/mingw-includes/mingw-includes.qbs new file mode 100644 index 0000000000000000000000000000000000000000..f6ae698a0cb6b887b931d41df7b7b12e8d4579f2 --- /dev/null +++ b/src/plugins/clangstaticanalyzer/unit-tests/mingw-includes/mingw-includes.qbs @@ -0,0 +1,5 @@ +import qbs + +CppApplication { + files: ["main.cpp"] +}