forked from qt-creator/qt-creator
Clang Static Analyzer: Extract ExtraToolChainInfo
Change-Id: I16527a4fe5a00327c97ae72f6b76a3daf86d60d1 Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com> Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
This commit is contained in:
@@ -71,7 +71,6 @@ ClangStaticAnalyzerRunControl::ClangStaticAnalyzerRunControl(
|
|||||||
const ProjectInfo &projectInfo)
|
const ProjectInfo &projectInfo)
|
||||||
: AnalyzerRunControl(runConfiguration, runMode)
|
: AnalyzerRunControl(runConfiguration, runMode)
|
||||||
, m_projectInfo(projectInfo)
|
, m_projectInfo(projectInfo)
|
||||||
, m_wordWidth(runConfiguration->abi().wordWidth())
|
|
||||||
, m_initialFilesToProcessSize(0)
|
, m_initialFilesToProcessSize(0)
|
||||||
, m_filesAnalyzed(0)
|
, m_filesAnalyzed(0)
|
||||||
, m_filesNotAnalyzed(0)
|
, m_filesNotAnalyzed(0)
|
||||||
@@ -80,7 +79,11 @@ ClangStaticAnalyzerRunControl::ClangStaticAnalyzerRunControl(
|
|||||||
BuildConfiguration *buildConfiguration = target->activeBuildConfiguration();
|
BuildConfiguration *buildConfiguration = target->activeBuildConfiguration();
|
||||||
QTC_ASSERT(buildConfiguration, return);
|
QTC_ASSERT(buildConfiguration, return);
|
||||||
m_environment = buildConfiguration->environment();
|
m_environment = buildConfiguration->environment();
|
||||||
m_targetTriple = ToolChainKitInformation::toolChain(target->kit())->originalTargetTriple();
|
|
||||||
|
ToolChain *toolChain = ToolChainKitInformation::toolChain(target->kit());
|
||||||
|
QTC_ASSERT(toolChain, return);
|
||||||
|
m_extraToolChainInfo.wordWidth = runConfiguration->abi().wordWidth();
|
||||||
|
m_extraToolChainInfo.targetTriple = toolChain->originalTargetTriple();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prependWordWidthArgumentIfNotIncluded(QStringList *arguments, unsigned char wordWidth)
|
static void prependWordWidthArgumentIfNotIncluded(QStringList *arguments, unsigned char wordWidth)
|
||||||
@@ -118,8 +121,7 @@ static void prependTargetTripleIfNotIncludedAndNotEmpty(QStringList *arguments,
|
|||||||
// Prepends -target if not already included.
|
// Prepends -target if not already included.
|
||||||
static QStringList tweakedArguments(const QString &filePath,
|
static QStringList tweakedArguments(const QString &filePath,
|
||||||
const QStringList &arguments,
|
const QStringList &arguments,
|
||||||
unsigned char wordWidth,
|
const ExtraToolChainInfo &extraParams)
|
||||||
const QString &targetTriple)
|
|
||||||
{
|
{
|
||||||
QStringList newArguments;
|
QStringList newArguments;
|
||||||
|
|
||||||
@@ -139,8 +141,8 @@ static QStringList tweakedArguments(const QString &filePath,
|
|||||||
}
|
}
|
||||||
QTC_CHECK(skip == false);
|
QTC_CHECK(skip == false);
|
||||||
|
|
||||||
prependWordWidthArgumentIfNotIncluded(&newArguments, wordWidth);
|
prependWordWidthArgumentIfNotIncluded(&newArguments, extraParams.wordWidth);
|
||||||
prependTargetTripleIfNotIncludedAndNotEmpty(&newArguments, targetTriple);
|
prependTargetTripleIfNotIncludedAndNotEmpty(&newArguments, extraParams.targetTriple);
|
||||||
|
|
||||||
return newArguments;
|
return newArguments;
|
||||||
}
|
}
|
||||||
@@ -167,8 +169,7 @@ class ClangStaticAnalyzerOptionsBuilder : public CompilerOptionsBuilder
|
|||||||
public:
|
public:
|
||||||
static QStringList build(const CppTools::ProjectPart &projectPart,
|
static QStringList build(const CppTools::ProjectPart &projectPart,
|
||||||
CppTools::ProjectFile::Kind fileKind,
|
CppTools::ProjectFile::Kind fileKind,
|
||||||
unsigned char wordWidth,
|
const ExtraToolChainInfo &extraParams)
|
||||||
const QString &targetTriple)
|
|
||||||
{
|
{
|
||||||
ClangStaticAnalyzerOptionsBuilder optionsBuilder(projectPart);
|
ClangStaticAnalyzerOptionsBuilder optionsBuilder(projectPart);
|
||||||
optionsBuilder.addLanguageOption(fileKind);
|
optionsBuilder.addLanguageOption(fileKind);
|
||||||
@@ -192,8 +193,8 @@ public:
|
|||||||
optionsBuilder.add(QLatin1String("-fPIC")); // TODO: Remove?
|
optionsBuilder.add(QLatin1String("-fPIC")); // TODO: Remove?
|
||||||
|
|
||||||
QStringList options = optionsBuilder.options();
|
QStringList options = optionsBuilder.options();
|
||||||
prependWordWidthArgumentIfNotIncluded(&options, wordWidth);
|
prependWordWidthArgumentIfNotIncluded(&options, extraParams.wordWidth);
|
||||||
prependTargetTripleIfNotIncludedAndNotEmpty(&options, targetTriple);
|
prependTargetTripleIfNotIncludedAndNotEmpty(&options, extraParams.targetTriple);
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
@@ -240,8 +241,7 @@ private:
|
|||||||
|
|
||||||
static AnalyzeUnits unitsToAnalyzeFromCompilerCallData(
|
static AnalyzeUnits unitsToAnalyzeFromCompilerCallData(
|
||||||
const ProjectInfo::CompilerCallData &compilerCallData,
|
const ProjectInfo::CompilerCallData &compilerCallData,
|
||||||
unsigned char wordWidth,
|
const ExtraToolChainInfo &extraParams)
|
||||||
const QString &targetTriple)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG) << "Taking arguments for analyzing from CompilerCallData.";
|
qCDebug(LOG) << "Taking arguments for analyzing from CompilerCallData.";
|
||||||
|
|
||||||
@@ -253,7 +253,7 @@ static AnalyzeUnits unitsToAnalyzeFromCompilerCallData(
|
|||||||
const QString file = it.key();
|
const QString file = it.key();
|
||||||
const QList<QStringList> compilerCalls = it.value();
|
const QList<QStringList> compilerCalls = it.value();
|
||||||
foreach (const QStringList &options, compilerCalls) {
|
foreach (const QStringList &options, compilerCalls) {
|
||||||
const QStringList arguments = tweakedArguments(file, options, wordWidth, targetTriple);
|
const QStringList arguments = tweakedArguments(file, options, extraParams);
|
||||||
unitsToAnalyze << AnalyzeUnit(file, arguments);
|
unitsToAnalyze << AnalyzeUnit(file, arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -262,8 +262,7 @@ static AnalyzeUnits unitsToAnalyzeFromCompilerCallData(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QList<ProjectPart::Ptr> projectParts,
|
static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QList<ProjectPart::Ptr> projectParts,
|
||||||
unsigned char wordWidth,
|
const ExtraToolChainInfo &extraParams)
|
||||||
const QString &targetTriple)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG) << "Taking arguments for analyzing from ProjectParts.";
|
qCDebug(LOG) << "Taking arguments for analyzing from ProjectParts.";
|
||||||
|
|
||||||
@@ -281,8 +280,7 @@ static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QList<ProjectPart::Ptr>
|
|||||||
const QStringList arguments
|
const QStringList arguments
|
||||||
= ClangStaticAnalyzerOptionsBuilder::build(*projectPart.data(),
|
= ClangStaticAnalyzerOptionsBuilder::build(*projectPart.data(),
|
||||||
file.kind,
|
file.kind,
|
||||||
wordWidth,
|
extraParams);
|
||||||
targetTriple);
|
|
||||||
unitsToAnalyze << AnalyzeUnit(file.path, arguments);
|
unitsToAnalyze << AnalyzeUnit(file.path, arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -297,15 +295,10 @@ AnalyzeUnits ClangStaticAnalyzerRunControl::sortedUnitsToAnalyze()
|
|||||||
|
|
||||||
AnalyzeUnits units;
|
AnalyzeUnits units;
|
||||||
const ProjectInfo::CompilerCallData compilerCallData = m_projectInfo.compilerCallData();
|
const ProjectInfo::CompilerCallData compilerCallData = m_projectInfo.compilerCallData();
|
||||||
if (compilerCallData.isEmpty()) {
|
if (compilerCallData.isEmpty())
|
||||||
units = unitsToAnalyzeFromProjectParts(m_projectInfo.projectParts(),
|
units = unitsToAnalyzeFromProjectParts(m_projectInfo.projectParts(), m_extraToolChainInfo);
|
||||||
m_wordWidth,
|
else
|
||||||
m_targetTriple);
|
units = unitsToAnalyzeFromCompilerCallData(compilerCallData, m_extraToolChainInfo);
|
||||||
} else {
|
|
||||||
units = unitsToAnalyzeFromCompilerCallData(compilerCallData,
|
|
||||||
m_wordWidth,
|
|
||||||
m_targetTriple);
|
|
||||||
}
|
|
||||||
|
|
||||||
Utils::sort(units, [](const AnalyzeUnit &a1, const AnalyzeUnit &a2) -> bool {
|
Utils::sort(units, [](const AnalyzeUnit &a1, const AnalyzeUnit &a2) -> bool {
|
||||||
return a1.file < a2.file;
|
return a1.file < a2.file;
|
||||||
|
@@ -48,6 +48,11 @@ struct AnalyzeUnit {
|
|||||||
};
|
};
|
||||||
typedef QList<AnalyzeUnit> AnalyzeUnits;
|
typedef QList<AnalyzeUnit> AnalyzeUnits;
|
||||||
|
|
||||||
|
struct ExtraToolChainInfo {
|
||||||
|
unsigned char wordWidth = 0;
|
||||||
|
QString targetTriple;
|
||||||
|
};
|
||||||
|
|
||||||
class ClangStaticAnalyzerRunControl : public Debugger::AnalyzerRunControl
|
class ClangStaticAnalyzerRunControl : public Debugger::AnalyzerRunControl
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -82,8 +87,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const CppTools::ProjectInfo m_projectInfo;
|
const CppTools::ProjectInfo m_projectInfo;
|
||||||
const unsigned char m_wordWidth;
|
ExtraToolChainInfo m_extraToolChainInfo;
|
||||||
QString m_targetTriple;
|
|
||||||
|
|
||||||
Utils::Environment m_environment;
|
Utils::Environment m_environment;
|
||||||
QString m_clangExecutable;
|
QString m_clangExecutable;
|
||||||
|
Reference in New Issue
Block a user