forked from qt-creator/qt-creator
Clang: Undefine language features as fix for MSVC2015/clang-3.8.0
This applies the following change for the clang code model, too.
commit d13d179524
Clang Static Analyzer: Workaround analyzing MSVC2015 projects with clang 3.8.0 II
Change-Id: Ia229d7e8b24c2e1c0a83d9a53c623ea1f79c4a06
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
This commit is contained in:
@@ -93,6 +93,7 @@ public:
|
||||
optionsBuilder.addOptionsForLanguage(/*checkForBorlandExtensions*/ true);
|
||||
|
||||
optionsBuilder.addToolchainAndProjectDefines();
|
||||
optionsBuilder.undefineCppLanguageFeatureMacrosForMsvc2015();
|
||||
|
||||
optionsBuilder.addPredefinedMacrosAndHeaderPathsOptions();
|
||||
optionsBuilder.addWrappedQtHeadersIncludePath();
|
||||
|
@@ -82,9 +82,7 @@ ClangStaticAnalyzerRunControl::ClangStaticAnalyzerRunControl(
|
||||
|
||||
ToolChain *toolChain = ToolChainKitInformation::toolChain(target->kit());
|
||||
QTC_ASSERT(toolChain, return);
|
||||
Abi abi = runConfiguration->abi();
|
||||
m_extraToolChainInfo.wordWidth = abi.wordWidth();
|
||||
m_extraToolChainInfo.isMsvc2015 = abi.osFlavor() == Abi::WindowsMsvc2015Flavor;
|
||||
m_extraToolChainInfo.wordWidth = runConfiguration->abi().wordWidth();
|
||||
m_extraToolChainInfo.targetTriple = toolChain->originalTargetTriple();
|
||||
}
|
||||
|
||||
@@ -142,54 +140,6 @@ QStringList inputAndOutputArgumentsRemoved(const QString &inputFile, const QStri
|
||||
return newArguments;
|
||||
}
|
||||
|
||||
static QStringList languageFeatureMacros()
|
||||
{
|
||||
// Collected with:
|
||||
// $ CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
|
||||
// $ D:\usr\llvm-3.8.0\bin\clang++.exe -fms-compatibility-version=19 -std=c++1y -dM -E D:\empty.cpp | grep __cpp_
|
||||
static QStringList macros {
|
||||
QLatin1String("__cpp_aggregate_nsdmi"),
|
||||
QLatin1String("__cpp_alias_templates"),
|
||||
QLatin1String("__cpp_attributes"),
|
||||
QLatin1String("__cpp_binary_literals"),
|
||||
QLatin1String("__cpp_constexpr"),
|
||||
QLatin1String("__cpp_decltype"),
|
||||
QLatin1String("__cpp_decltype_auto"),
|
||||
QLatin1String("__cpp_delegating_constructors"),
|
||||
QLatin1String("__cpp_digit_separators"),
|
||||
QLatin1String("__cpp_generic_lambdas"),
|
||||
QLatin1String("__cpp_inheriting_constructors"),
|
||||
QLatin1String("__cpp_init_captures"),
|
||||
QLatin1String("__cpp_initializer_lists"),
|
||||
QLatin1String("__cpp_lambdas"),
|
||||
QLatin1String("__cpp_nsdmi"),
|
||||
QLatin1String("__cpp_range_based_for"),
|
||||
QLatin1String("__cpp_raw_strings"),
|
||||
QLatin1String("__cpp_ref_qualifiers"),
|
||||
QLatin1String("__cpp_return_type_deduction"),
|
||||
QLatin1String("__cpp_rtti"),
|
||||
QLatin1String("__cpp_rvalue_references"),
|
||||
QLatin1String("__cpp_static_assert"),
|
||||
QLatin1String("__cpp_unicode_characters"),
|
||||
QLatin1String("__cpp_unicode_literals"),
|
||||
QLatin1String("__cpp_user_defined_literals"),
|
||||
QLatin1String("__cpp_variable_templates"),
|
||||
QLatin1String("__cpp_variadic_templates"),
|
||||
};
|
||||
|
||||
return macros;
|
||||
}
|
||||
|
||||
static void undefineCppLanguageFeatureMacrosForMsvc2015(QStringList *arguments, bool isMsvc2015)
|
||||
{
|
||||
QTC_ASSERT(arguments, return);
|
||||
|
||||
if (isMsvc2015) {
|
||||
foreach (const QString ¯oName, languageFeatureMacros())
|
||||
arguments->append(QLatin1String("/U") + macroName);
|
||||
}
|
||||
}
|
||||
|
||||
static QString createLanguageOptionMsvc(ProjectFile::Kind fileKind)
|
||||
{
|
||||
switch (fileKind) {
|
||||
@@ -230,6 +180,7 @@ public:
|
||||
optionsBuilder.addDefine("#define _X86INTRIN_H_INCLUDED\n");
|
||||
|
||||
optionsBuilder.addToolchainAndProjectDefines();
|
||||
optionsBuilder.undefineCppLanguageFeatureMacrosForMsvc2015();
|
||||
optionsBuilder.addHeaderPathOptions();
|
||||
optionsBuilder.addMsvcCompatibilityVersion();
|
||||
|
||||
@@ -240,7 +191,6 @@ public:
|
||||
|
||||
QStringList options = optionsBuilder.options();
|
||||
prependWordWidthArgumentIfNotIncluded(&options, extraParams.wordWidth);
|
||||
undefineCppLanguageFeatureMacrosForMsvc2015(&options, extraParams.isMsvc2015);
|
||||
|
||||
return options;
|
||||
}
|
||||
@@ -303,6 +253,15 @@ static QStringList createMsCompatibilityVersionOption(const ProjectPart &project
|
||||
return option;
|
||||
}
|
||||
|
||||
static QStringList createOptionsToUndefineCppLanguageFeatureMacrosForMsvc2015(
|
||||
const ProjectPart &projectPart)
|
||||
{
|
||||
ClangStaticAnalyzerOptionsBuilder optionsBuilder(projectPart);
|
||||
optionsBuilder.undefineCppLanguageFeatureMacrosForMsvc2015();
|
||||
|
||||
return optionsBuilder.options();
|
||||
}
|
||||
|
||||
static QStringList tweakedArguments(const ProjectPart &projectPart,
|
||||
const QString &filePath,
|
||||
const QStringList &arguments,
|
||||
@@ -312,7 +271,7 @@ static QStringList tweakedArguments(const ProjectPart &projectPart,
|
||||
prependWordWidthArgumentIfNotIncluded(&newArguments, extraParams.wordWidth);
|
||||
prependTargetTripleIfNotIncludedAndNotEmpty(&newArguments, extraParams.targetTriple);
|
||||
newArguments.append(createMsCompatibilityVersionOption(projectPart));
|
||||
undefineCppLanguageFeatureMacrosForMsvc2015(&newArguments, extraParams.isMsvc2015);
|
||||
newArguments.append(createOptionsToUndefineCppLanguageFeatureMacrosForMsvc2015(projectPart));
|
||||
|
||||
return newArguments;
|
||||
}
|
||||
|
@@ -51,7 +51,6 @@ typedef QList<AnalyzeUnit> AnalyzeUnits;
|
||||
struct ExtraToolChainInfo {
|
||||
unsigned char wordWidth = 0;
|
||||
QString targetTriple;
|
||||
bool isMsvc2015 = false;
|
||||
};
|
||||
|
||||
class ClangStaticAnalyzerRunControl : public Debugger::AnalyzerRunControl
|
||||
|
@@ -283,6 +283,55 @@ void CompilerOptionsBuilder::addMsvcCompatibilityVersion()
|
||||
}
|
||||
}
|
||||
|
||||
static QStringList languageFeatureMacros()
|
||||
{
|
||||
// Collected with:
|
||||
// $ CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
|
||||
// $ D:\usr\llvm-3.8.0\bin\clang++.exe -fms-compatibility-version=19 -std=c++1y -dM -E D:\empty.cpp | grep __cpp_
|
||||
static QStringList macros {
|
||||
QLatin1String("__cpp_aggregate_nsdmi"),
|
||||
QLatin1String("__cpp_alias_templates"),
|
||||
QLatin1String("__cpp_attributes"),
|
||||
QLatin1String("__cpp_binary_literals"),
|
||||
QLatin1String("__cpp_constexpr"),
|
||||
QLatin1String("__cpp_decltype"),
|
||||
QLatin1String("__cpp_decltype_auto"),
|
||||
QLatin1String("__cpp_delegating_constructors"),
|
||||
QLatin1String("__cpp_digit_separators"),
|
||||
QLatin1String("__cpp_generic_lambdas"),
|
||||
QLatin1String("__cpp_inheriting_constructors"),
|
||||
QLatin1String("__cpp_init_captures"),
|
||||
QLatin1String("__cpp_initializer_lists"),
|
||||
QLatin1String("__cpp_lambdas"),
|
||||
QLatin1String("__cpp_nsdmi"),
|
||||
QLatin1String("__cpp_range_based_for"),
|
||||
QLatin1String("__cpp_raw_strings"),
|
||||
QLatin1String("__cpp_ref_qualifiers"),
|
||||
QLatin1String("__cpp_return_type_deduction"),
|
||||
QLatin1String("__cpp_rtti"),
|
||||
QLatin1String("__cpp_rvalue_references"),
|
||||
QLatin1String("__cpp_static_assert"),
|
||||
QLatin1String("__cpp_unicode_characters"),
|
||||
QLatin1String("__cpp_unicode_literals"),
|
||||
QLatin1String("__cpp_user_defined_literals"),
|
||||
QLatin1String("__cpp_variable_templates"),
|
||||
QLatin1String("__cpp_variadic_templates"),
|
||||
};
|
||||
|
||||
return macros;
|
||||
}
|
||||
|
||||
void CompilerOptionsBuilder::undefineCppLanguageFeatureMacrosForMsvc2015()
|
||||
{
|
||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID
|
||||
&& m_projectPart.isMsvc2015Toolchain) {
|
||||
// Undefine the language feature macros that are pre-defined in clang-cl 3.8.0,
|
||||
// but not in MSVC2015's cl.exe.
|
||||
foreach (const QString ¯oName, languageFeatureMacros())
|
||||
m_options.append(QLatin1String("/U") + macroName);
|
||||
}
|
||||
}
|
||||
|
||||
QString CompilerOptionsBuilder::includeOption() const
|
||||
{
|
||||
return QLatin1String("-I");
|
||||
|
@@ -52,6 +52,7 @@ public:
|
||||
virtual void addOptionsForLanguage(bool checkForBorlandExtensions = true);
|
||||
|
||||
void addMsvcCompatibilityVersion();
|
||||
void undefineCppLanguageFeatureMacrosForMsvc2015();
|
||||
|
||||
protected:
|
||||
virtual bool excludeDefineLine(const QByteArray &defineLine) const;
|
||||
|
@@ -32,6 +32,7 @@ namespace CppTools {
|
||||
|
||||
ProjectPart::ProjectPart()
|
||||
: project(0)
|
||||
, isMsvc2015Toolchain(false)
|
||||
, languageVersion(CXX14)
|
||||
, languageExtensions(NoExtensions)
|
||||
, qtVersion(UnknownQt)
|
||||
|
@@ -104,6 +104,7 @@ public: // fields
|
||||
QByteArray projectDefines;
|
||||
QByteArray toolchainDefines;
|
||||
Core::Id toolchainType;
|
||||
bool isMsvc2015Toolchain;
|
||||
QString targetTriple;
|
||||
ProjectPartHeaderPaths headerPaths;
|
||||
QStringList precompiledHeaders;
|
||||
|
@@ -28,10 +28,12 @@
|
||||
#include "cppprojectfile.h"
|
||||
#include "cpptoolsconstants.h"
|
||||
|
||||
#include <projectexplorer/abi.h>
|
||||
#include <projectexplorer/headerpath.h>
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/runconfiguration.h>
|
||||
#include <projectexplorer/target.h>
|
||||
#include <projectexplorer/toolchain.h>
|
||||
|
||||
@@ -279,6 +281,18 @@ QString targetTriple(ProjectExplorer::Project *project, const Core::Id &toolchai
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool projectHasMsvc2015Toolchain(ProjectExplorer::Project *project)
|
||||
{
|
||||
if (project) {
|
||||
if (ProjectExplorer::Target *target = project->activeTarget()) {
|
||||
if (ProjectExplorer::RunConfiguration *runConfig = target->activeRunConfiguration())
|
||||
return runConfig->abi().osFlavor() == ProjectExplorer::Abi::WindowsMsvc2015Flavor;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -341,6 +355,7 @@ void ProjectPartBuilder::evaluateProjectPartToolchain(
|
||||
|
||||
projectPart->toolchainDefines = toolChain->predefinedMacros(commandLineFlags);
|
||||
projectPart->toolchainType = toolChain->typeId();
|
||||
projectPart->isMsvc2015Toolchain = projectHasMsvc2015Toolchain(projectPart->project);
|
||||
projectPart->targetTriple = targetTriple(projectPart->project, toolChain->typeId());
|
||||
projectPart->updateLanguageFeatures();
|
||||
}
|
||||
|
Reference in New Issue
Block a user