Commit daf08d87 authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang Static Analyzer: Workaround analyzing MSVC2015 projects with clang 3.8.0

Clang 3.8.0 does not detect the MSVC2015 build environment properly. Running

  $ clang.exe -v -fsyntax-only empty.cpp

shows

  -fms-compatibility-version=18 (=MSVC2013)

instead of the expected

  -fms-compatibility-version=19 (=MSVC2015)

Workaround this by setting the version explicitly for MSVC2015 toolchains. This
fixes parse issues with char16_t and friends.

We do not explicitly check for the clang version since clang 3.6.2 is broken
for MSVC2015 anyway and we do not know whether clang 3.8.1 will come with a
fix.

Task-number: QTCREATORBUG-15940
Change-Id: Ibe61af25f6d74f134cc9f9681db5a4d19ac67417
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@theqtcompany.com>
parent 1bf5ba84
......@@ -82,7 +82,9 @@ ClangStaticAnalyzerRunControl::ClangStaticAnalyzerRunControl(
ToolChain *toolChain = ToolChainKitInformation::toolChain(target->kit());
QTC_ASSERT(toolChain, return);
m_extraToolChainInfo.wordWidth = runConfiguration->abi().wordWidth();
Abi abi = runConfiguration->abi();
m_extraToolChainInfo.wordWidth = abi.wordWidth();
m_extraToolChainInfo.isMsvc2015 = abi.osFlavor() == Abi::WindowsMsvc2015Flavor;
m_extraToolChainInfo.targetTriple = toolChain->originalTargetTriple();
}
......@@ -140,6 +142,14 @@ QStringList inputAndOutputArgumentsRemoved(const QString &inputFile, const QStri
return newArguments;
}
static void appendMsCompatibility2015OptionForMsvc2015(QStringList *arguments, bool isMsvc2015)
{
QTC_ASSERT(arguments, return);
if (isMsvc2015)
arguments->append(QLatin1String("-fms-compatibility-version=19"));
}
static QStringList tweakedArguments(const QString &filePath,
const QStringList &arguments,
const ExtraToolChainInfo &extraParams)
......@@ -147,6 +157,7 @@ static QStringList tweakedArguments(const QString &filePath,
QStringList newArguments = inputAndOutputArgumentsRemoved(filePath, arguments);
prependWordWidthArgumentIfNotIncluded(&newArguments, extraParams.wordWidth);
prependTargetTripleIfNotIncludedAndNotEmpty(&newArguments, extraParams.targetTriple);
appendMsCompatibility2015OptionForMsvc2015(&newArguments, extraParams.isMsvc2015);
return newArguments;
}
......@@ -199,6 +210,7 @@ public:
QStringList options = optionsBuilder.options();
prependWordWidthArgumentIfNotIncluded(&options, extraParams.wordWidth);
prependTargetTripleIfNotIncludedAndNotEmpty(&options, extraParams.targetTriple);
appendMsCompatibility2015OptionForMsvc2015(&options, extraParams.isMsvc2015);
return options;
}
......
......@@ -51,6 +51,7 @@ typedef QList<AnalyzeUnit> AnalyzeUnits;
struct ExtraToolChainInfo {
unsigned char wordWidth = 0;
QString targetTriple;
bool isMsvc2015 = false;
};
class ClangStaticAnalyzerRunControl : public Debugger::AnalyzerRunControl
......
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