Commit b0a49ca1 authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang: Fix parsing MSVC's crtdefs.h for 64 Bit

...by specifying the word width, as for the Clang Static Analyzer.

This has gone unnoticed so far because it looks like that the error diagnostic
from the bug report can be extracted with libclang (as shown in the info bar),
but is not printed from libclang or clang.exe itself.

Task-number: QTCREATORBUG-17130
Change-Id: Ia7a5ee3825c7211cdf80c2166a9eb454ce48cac1
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
Reviewed-by: Christian Kandeler's avatarChristian Kandeler <christian.kandeler@qt.io>
parent ddf1072d
......@@ -89,6 +89,7 @@ public:
LibClangOptionsBuilder optionsBuilder(*projectPart.data());
optionsBuilder.addWordWidth();
optionsBuilder.addTargetTriple();
optionsBuilder.addLanguageOption(fileKind);
optionsBuilder.addOptionsForLanguage(/*checkForBorlandExtensions*/ true);
......
......@@ -124,6 +124,7 @@ Utils::SmallStringVector RefactoringCompilerOptionsBuilder::build(CppTools::Proj
RefactoringCompilerOptionsBuilder optionsBuilder(projectPart);
optionsBuilder.addWordWidth();
optionsBuilder.addTargetTriple();
optionsBuilder.addLanguageOption(fileKind);
optionsBuilder.addOptionsForLanguage(/*checkForBorlandExtensions*/ true);
......
......@@ -86,18 +86,18 @@ ClangStaticAnalyzerRunControl::ClangStaticAnalyzerRunControl(
ToolChain *toolChain = ToolChainKitInformation::toolChain(target->kit(), ToolChain::Language::Cxx);
QTC_ASSERT(toolChain, return);
m_extraToolChainInfo.wordWidth = toolChain->targetAbi().wordWidth();
m_extraToolChainInfo.targetTriple = toolChain->originalTargetTriple();
m_targetTriple = toolChain->originalTargetTriple();
}
static void prependWordWidthArgumentIfNotIncluded(QStringList *arguments, unsigned char wordWidth)
static void prependWordWidthArgumentIfNotIncluded(QStringList *arguments,
ProjectPart::ToolChainWordWidth wordWidth)
{
QTC_ASSERT(arguments, return);
const QString m64Argument = QLatin1String("-m64");
const QString m32Argument = QLatin1String("-m32");
const QString argument = wordWidth == 64 ? m64Argument : m32Argument;
const QString argument = wordWidth == ProjectPart::WordWidth64Bit ? m64Argument : m32Argument;
if (!arguments->contains(argument))
arguments->prepend(argument);
......@@ -165,11 +165,11 @@ class ClangStaticAnalyzerOptionsBuilder : public CompilerOptionsBuilder
{
public:
static QStringList build(const CppTools::ProjectPart &projectPart,
CppTools::ProjectFile::Kind fileKind,
const ExtraToolChainInfo &extraParams)
CppTools::ProjectFile::Kind fileKind)
{
ClangStaticAnalyzerOptionsBuilder optionsBuilder(projectPart);
optionsBuilder.addWordWidth();
optionsBuilder.addTargetTriple();
optionsBuilder.addLanguageOption(fileKind);
optionsBuilder.addOptionsForLanguage(false);
......@@ -195,10 +195,7 @@ public:
if (type != ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID)
optionsBuilder.add(QLatin1String("-fPIC")); // TODO: Remove?
QStringList options = optionsBuilder.options();
prependWordWidthArgumentIfNotIncluded(&options, extraParams.wordWidth);
return options;
return optionsBuilder.options();
}
ClangStaticAnalyzerOptionsBuilder(const CppTools::ProjectPart &projectPart)
......@@ -325,11 +322,11 @@ static QStringList createHeaderPathsOptionsForClangOnMac(const ProjectPart &proj
static QStringList tweakedArguments(const ProjectPart &projectPart,
const QString &filePath,
const QStringList &arguments,
const ExtraToolChainInfo &extraParams)
const QString &targetTriple)
{
QStringList newArguments = inputAndOutputArgumentsRemoved(filePath, arguments);
prependWordWidthArgumentIfNotIncluded(&newArguments, extraParams.wordWidth);
prependTargetTripleIfNotIncludedAndNotEmpty(&newArguments, extraParams.targetTriple);
prependWordWidthArgumentIfNotIncluded(&newArguments, projectPart.toolChainWordWidth);
prependTargetTripleIfNotIncludedAndNotEmpty(&newArguments, targetTriple);
newArguments.append(createHeaderPathsOptionsForClangOnMac(projectPart));
newArguments.append(createMsCompatibilityVersionOption(projectPart));
newArguments.append(createOptionsToUndefineClangVersionMacrosForMsvc(projectPart));
......@@ -341,7 +338,7 @@ static QStringList tweakedArguments(const ProjectPart &projectPart,
static AnalyzeUnits unitsToAnalyzeFromCompilerCallData(
const QHash<QString, ProjectPart::Ptr> &projectFileToProjectPart,
const ProjectInfo::CompilerCallData &compilerCallData,
const ExtraToolChainInfo &extraParams)
const QString &targetTriple)
{
qCDebug(LOG) << "Taking arguments for analyzing from CompilerCallData.";
......@@ -361,7 +358,7 @@ static AnalyzeUnits unitsToAnalyzeFromCompilerCallData(
const QStringList arguments = tweakedArguments(*projectPart,
file,
options,
extraParams);
targetTriple);
unitsToAnalyze << AnalyzeUnit(file, arguments);
}
}
......@@ -370,8 +367,7 @@ static AnalyzeUnits unitsToAnalyzeFromCompilerCallData(
return unitsToAnalyze;
}
static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QList<ProjectPart::Ptr> projectParts,
const ExtraToolChainInfo &extraParams)
static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QList<ProjectPart::Ptr> projectParts)
{
qCDebug(LOG) << "Taking arguments for analyzing from ProjectParts.";
......@@ -387,9 +383,7 @@ static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QList<ProjectPart::Ptr>
QTC_CHECK(file.kind != ProjectFile::Unclassified);
if (ProjectFile::isSource(file.kind)) {
const QStringList arguments
= ClangStaticAnalyzerOptionsBuilder::build(*projectPart.data(),
file.kind,
extraParams);
= ClangStaticAnalyzerOptionsBuilder::build(*projectPart.data(), file.kind);
unitsToAnalyze << AnalyzeUnit(file.path, arguments);
}
}
......@@ -418,13 +412,13 @@ AnalyzeUnits ClangStaticAnalyzerRunControl::sortedUnitsToAnalyze()
AnalyzeUnits units;
const ProjectInfo::CompilerCallData compilerCallData = m_projectInfo.compilerCallData();
if (compilerCallData.isEmpty()) {
units = unitsToAnalyzeFromProjectParts(m_projectInfo.projectParts(), m_extraToolChainInfo);
units = unitsToAnalyzeFromProjectParts(m_projectInfo.projectParts());
} else {
const QHash<QString, ProjectPart::Ptr> projectFileToProjectPart
= generateProjectFileToProjectPartMapping(m_projectInfo.projectParts());
units = unitsToAnalyzeFromCompilerCallData(projectFileToProjectPart,
compilerCallData,
m_extraToolChainInfo);
m_targetTriple);
}
Utils::sort(units, &AnalyzeUnit::file);
......
......@@ -47,11 +47,6 @@ struct AnalyzeUnit {
};
typedef QList<AnalyzeUnit> AnalyzeUnits;
struct ExtraToolChainInfo {
unsigned char wordWidth = 0;
QString targetTriple;
};
class ClangStaticAnalyzerRunControl : public ProjectExplorer::RunControl
{
Q_OBJECT
......@@ -88,7 +83,7 @@ private:
private:
const CppTools::ProjectInfo m_projectInfo;
ExtraToolChainInfo m_extraToolChainInfo;
QString m_targetTriple;
Utils::Environment m_environment;
QString m_clangExecutable;
......
......@@ -87,6 +87,14 @@ void CompilerOptionsBuilder::addDefine(const QByteArray &defineDirective)
m_options.append(defineDirectiveToDefineOption(defineDirective));
}
void CompilerOptionsBuilder::addWordWidth()
{
const QString argument = m_projectPart.toolChainWordWidth == ProjectPart::WordWidth64Bit
? QLatin1String("-m64")
: QLatin1String("-m32");
add(argument);
}
void CompilerOptionsBuilder::addTargetTriple()
{
if (!m_projectPart.targetTriple.isEmpty()) {
......
......@@ -44,6 +44,7 @@ public:
void addDefine(const QByteArray &defineDirective);
// Add options based on project part
void addWordWidth();
virtual void addTargetTriple();
virtual void enableExceptions();
void addHeaderPathOptions();
......
......@@ -32,6 +32,7 @@ namespace CppTools {
ProjectPart::ProjectPart()
: project(0)
, toolChainWordWidth(WordWidth32Bit)
, isMsvc2015Toolchain(false)
, languageVersion(CXX14)
, languageExtensions(NoExtensions)
......
......@@ -81,6 +81,11 @@ public: // Types
Qt5 = 2
};
enum ToolChainWordWidth {
WordWidth32Bit,
WordWidth64Bit,
};
using Ptr = QSharedPointer<ProjectPart>;
......@@ -103,6 +108,7 @@ public: // fields
QByteArray projectDefines;
QByteArray toolchainDefines;
Core::Id toolchainType;
ToolChainWordWidth toolChainWordWidth;
bool isMsvc2015Toolchain;
QString targetTriple;
ProjectPartHeaderPaths headerPaths;
......
......@@ -343,6 +343,9 @@ void ProjectPartBuilder::evaluateProjectPartToolchain(
projectPart->toolchainType = toolChain->typeId();
projectPart->isMsvc2015Toolchain
= toolChain->targetAbi().osFlavor() == ProjectExplorer::Abi::WindowsMsvc2015Flavor;
projectPart->toolChainWordWidth = toolChain->targetAbi().wordWidth() == 64
? ProjectPart::WordWidth64Bit
: ProjectPart::WordWidth32Bit;
projectPart->targetTriple = targetTriple(projectPart->project, toolChain->typeId());
projectPart->updateLanguageFeatures();
}
......
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