From 08f0d37c174ad8f41c51fb9b89d6b364277624c4 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Thu, 7 Jul 2016 10:51:41 +0200 Subject: [PATCH] ClangStaticAnalyzer: Undefine clang version macros for MSVC Kits This fixes parsing of Qt 5.7.0 headers with a MSVC Kit. Re-produce with: 1) Open qt-essential-includes.pro or the *.qbs and configure it with a Qt 5.7.0 MSVC2013 Kit. 2) Run the analyzer. Errors during analyzing occur in qtypetraits.h [1] because * Q_COMPILER_UNICODE_STRINGS is defined in qcompilerdetection.h because... * Q_CC_CLANG is defined because... * __clang* is defined. Undefine the __clang* macros so the "right" compiler will be detected. [1] In file included from D:\dev\creator\creator-4.1\src\plugins\clangstaticanalyzer\unit-tests\qt-essential-includes\main.cpp:1: In file included from D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include/QtCore\QtCore:4: In file included from D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include/QtCore/qabstractanimation.h:43: In file included from D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include\QtCore/qobject.h:46: In file included from D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include\QtCore/qobjectdefs.h:48: In file included from D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include\QtCore/qnamespace.h:43: In file included from D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include\QtCore/qglobal.h:1139: In file included from D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include\QtCore/qtypeinfo.h:41: D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include\QtCore/qtypetraits.h(251,19) : error: redefinition of 'QtPrivate::is_integral' template<> struct is_integral : true_type { }; ^~~~~~~~~~~~~~~~~~~~~ D:/usr/qt-5.7.0-msvc2013_32/5.7/msvc2013/include\QtCore/qtypetraits.h(235,19) : note: previous definition is here template<> struct is_integral : true_type { }; Change-Id: I10da2a1daa6f5ea2828f7ea4bcf594050a585b61 Reviewed-by: Christian Kandeler --- .../clangstaticanalyzerruncontrol.cpp | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp b/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp index ad51016af68..e938e547b36 100644 --- a/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp +++ b/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp @@ -184,6 +184,7 @@ public: optionsBuilder.addDefine("#define _X86INTRIN_H_INCLUDED\n"); optionsBuilder.addToolchainAndProjectDefines(); + optionsBuilder.undefineClangVersionMacrosForMsvc(); optionsBuilder.undefineCppLanguageFeatureMacrosForMsvc2015(); optionsBuilder.addHeaderPathOptions(); optionsBuilder.addMsvcCompatibilityVersion(); @@ -203,6 +204,23 @@ public: { } +public: + void undefineClangVersionMacrosForMsvc() + { + if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) { + static QStringList macroNames { + "__clang__", + "__clang_major__", + "__clang_minor__", + "__clang_patchlevel__", + "__clang_version__" + }; + + foreach (const QString ¯oName, macroNames) + add(QLatin1String("/U") + macroName); + } + } + private: void addTargetTriple() override { @@ -272,6 +290,14 @@ static QStringList createOptionsToUndefineCppLanguageFeatureMacrosForMsvc2015( return optionsBuilder.options(); } +static QStringList createOptionsToUndefineClangVersionMacrosForMsvc(const ProjectPart &projectPart) +{ + ClangStaticAnalyzerOptionsBuilder optionsBuilder(projectPart); + optionsBuilder.undefineClangVersionMacrosForMsvc(); + + return optionsBuilder.options(); +} + static QStringList tweakedArguments(const ProjectPart &projectPart, const QString &filePath, const QStringList &arguments, @@ -281,6 +307,7 @@ static QStringList tweakedArguments(const ProjectPart &projectPart, prependWordWidthArgumentIfNotIncluded(&newArguments, extraParams.wordWidth); prependTargetTripleIfNotIncludedAndNotEmpty(&newArguments, extraParams.targetTriple); newArguments.append(createMsCompatibilityVersionOption(projectPart)); + newArguments.append(createOptionsToUndefineClangVersionMacrosForMsvc(projectPart)); newArguments.append(createOptionsToUndefineCppLanguageFeatureMacrosForMsvc2015(projectPart)); return newArguments;