Commit 5b48bd04 authored by Ivan Donchevskii's avatar Ivan Donchevskii

Clang: fix clang static analyzer on Windows

1) mingw kit + qmake: do not add target includes
not to override clang paths (for intrinsics and more)
2) msvc kit + qbs: remove target option from
clang-cl arguments

Change-Id: Ifb494ee61ae2d39e957cff31dbd647c66910be17
Reviewed-by: Nikolai Kosjar's avatarNikolai Kosjar <nikolai.kosjar@qt.io>
parent 88e7af8a
...@@ -161,7 +161,8 @@ static void prependTargetTripleIfNotIncludedAndNotEmpty(QStringList *arguments, ...@@ -161,7 +161,8 @@ static void prependTargetTripleIfNotIncludedAndNotEmpty(QStringList *arguments,
} }
// Removes (1) inputFile (2) -o <somePath>. // Removes (1) inputFile (2) -o <somePath>.
QStringList inputAndOutputArgumentsRemoved(const QString &inputFile, const QStringList &arguments) QStringList inputAndOutputArgumentsRemoved(const QString &inputFile, const QStringList &arguments,
bool isMsvc)
{ {
QStringList newArguments; QStringList newArguments;
...@@ -173,6 +174,9 @@ QStringList inputAndOutputArgumentsRemoved(const QString &inputFile, const QStri ...@@ -173,6 +174,9 @@ QStringList inputAndOutputArgumentsRemoved(const QString &inputFile, const QStri
} else if (argument == QLatin1String("-o")) { } else if (argument == QLatin1String("-o")) {
skip = true; skip = true;
continue; continue;
} else if (isMsvc && argument == QLatin1String("-target")) {
skip = true;
continue;
} else if (QDir::fromNativeSeparators(argument) == inputFile) { } else if (QDir::fromNativeSeparators(argument) == inputFile) {
continue; // TODO: Let it in? continue; // TODO: Let it in?
} }
...@@ -233,11 +237,23 @@ public: ...@@ -233,11 +237,23 @@ public:
ClangStaticAnalyzerOptionsBuilder(const CppTools::ProjectPart &projectPart) ClangStaticAnalyzerOptionsBuilder(const CppTools::ProjectPart &projectPart)
: CompilerOptionsBuilder(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: 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() void undefineClangVersionMacrosForMsvc()
{ {
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) { if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
...@@ -260,7 +276,7 @@ private: ...@@ -260,7 +276,7 @@ private:
// For MSVC toolchains we use clang-cl.exe, so there is nothing to do here since // 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 // 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) // 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(); CompilerOptionsBuilder::addTargetTriple();
} }
...@@ -317,6 +333,7 @@ private: ...@@ -317,6 +333,7 @@ private:
private: private:
bool m_isMsvcToolchain; bool m_isMsvcToolchain;
bool m_isMinGWToolchain;
}; };
static QStringList createMsCompatibilityVersionOption(const ProjectPart &projectPart) static QStringList createMsCompatibilityVersionOption(const ProjectPart &projectPart)
...@@ -364,9 +381,12 @@ static QStringList tweakedArguments(const ProjectPart &projectPart, ...@@ -364,9 +381,12 @@ static QStringList tweakedArguments(const ProjectPart &projectPart,
const QStringList &arguments, const QStringList &arguments,
const QString &targetTriple) 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); prependWordWidthArgumentIfNotIncluded(&newArguments, projectPart.toolChainWordWidth);
prependTargetTripleIfNotIncludedAndNotEmpty(&newArguments, targetTriple); if (!isMsvc)
prependTargetTripleIfNotIncludedAndNotEmpty(&newArguments, targetTriple);
newArguments.append(createHeaderPathsOptionsForClangOnMac(projectPart)); newArguments.append(createHeaderPathsOptionsForClangOnMac(projectPart));
newArguments.append(createMsCompatibilityVersionOption(projectPart)); newArguments.append(createMsCompatibilityVersionOption(projectPart));
newArguments.append(createOptionsToUndefineClangVersionMacrosForMsvc(projectPart)); newArguments.append(createOptionsToUndefineClangVersionMacrosForMsvc(projectPart));
......
...@@ -75,6 +75,13 @@ void ClangStaticAnalyzerUnitTests::testProject() ...@@ -75,6 +75,13 @@ void ClangStaticAnalyzerUnitTests::testProject()
{ {
QFETCH(QString, projectFilePath); QFETCH(QString, projectFilePath);
QFETCH(int, expectedDiagCount); 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; CppTools::Tests::ProjectOpenerAndCloser projectManager;
const CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true); const CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true);
...@@ -107,6 +114,9 @@ void ClangStaticAnalyzerUnitTests::testProject_data() ...@@ -107,6 +114,9 @@ void ClangStaticAnalyzerUnitTests::testProject_data()
addTestRow("qt-essential-includes/qt-essential-includes.qbs", 0); addTestRow("qt-essential-includes/qt-essential-includes.qbs", 0);
addTestRow("qt-essential-includes/qt-essential-includes.pro", 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, void ClangStaticAnalyzerUnitTests::addTestRow(const QByteArray &relativeFilePath,
......
#include <cstddef>
#include "intrin.h"
int main(int argc, char *argv[])
{
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment