From 57ac8d96c76b322c1b28c0cd4ed1d13e7b6056d2 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Mon, 17 Oct 2016 12:06:35 +0200 Subject: [PATCH] Clang: Avoid running into gcc/mingw intrinsics Same as for the Clang Static Analyzer, so move the implementation into the base class and use it. 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. Change-Id: I5b714ba374c5fdefe234faf012a3515e96c9a08c Reviewed-by: Christian Kandeler --- src/plugins/clangcodemodel/clangutils.cpp | 1 + .../refactoringcompileroptionsbuilder.cpp | 1 + .../clangstaticanalyzerruncontrol.cpp | 9 +-------- src/plugins/cpptools/compileroptionsbuilder.cpp | 14 ++++++++++++++ src/plugins/cpptools/compileroptionsbuilder.h | 2 ++ 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/plugins/clangcodemodel/clangutils.cpp b/src/plugins/clangcodemodel/clangutils.cpp index 943b731d907..573d1be1fd1 100644 --- a/src/plugins/clangcodemodel/clangutils.cpp +++ b/src/plugins/clangcodemodel/clangutils.cpp @@ -95,6 +95,7 @@ public: optionsBuilder.addOptionsForLanguage(/*checkForBorlandExtensions*/ true); optionsBuilder.enableExceptions(); + optionsBuilder.addDefineToAvoidIncludingGccOrMinGwIntrinsics(); optionsBuilder.addToolchainAndProjectDefines(); optionsBuilder.undefineCppLanguageFeatureMacrosForMsvc2015(); diff --git a/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.cpp b/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.cpp index 64feefa576f..ca79ca5e4ab 100644 --- a/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.cpp +++ b/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.cpp @@ -130,6 +130,7 @@ Utils::SmallStringVector RefactoringCompilerOptionsBuilder::build(CppTools::Proj optionsBuilder.addOptionsForLanguage(/*checkForBorlandExtensions*/ true); optionsBuilder.enableExceptions(); + optionsBuilder.addDefineToAvoidIncludingGccOrMinGwIntrinsics(); optionsBuilder.addToolchainAndProjectDefines(); optionsBuilder.undefineCppLanguageFeatureMacrosForMsvc2015(); diff --git a/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp b/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp index 1577db6bec0..4185b6bfaa0 100644 --- a/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp +++ b/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp @@ -175,15 +175,8 @@ public: optionsBuilder.addOptionsForLanguage(false); optionsBuilder.enableExceptions(); - // In gcc headers, lots of built-ins are referenced that clang does not understand. - // Therefore, prevent the inclusion of the header that references them. Of course, this - // will break if code actually requires stuff from there, but that should be the less common - // case. + optionsBuilder.addDefineToAvoidIncludingGccOrMinGwIntrinsics(); const Core::Id type = projectPart.toolchainType; - if (type == ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID - || type == ProjectExplorer::Constants::GCC_TOOLCHAIN_TYPEID) - optionsBuilder.addDefine("#define _X86INTRIN_H_INCLUDED"); - if (type != ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) optionsBuilder.addDefines(projectPart.toolchainDefines); optionsBuilder.addDefines(projectPart.projectDefines); diff --git a/src/plugins/cpptools/compileroptionsbuilder.cpp b/src/plugins/cpptools/compileroptionsbuilder.cpp index 68a2586c0d4..c62feb94cd2 100644 --- a/src/plugins/cpptools/compileroptionsbuilder.cpp +++ b/src/plugins/cpptools/compileroptionsbuilder.cpp @@ -270,6 +270,20 @@ void CompilerOptionsBuilder::addOptionsForLanguage(bool checkForBorlandExtension m_options.append(opts); } +void CompilerOptionsBuilder::addDefineToAvoidIncludingGccOrMinGwIntrinsics() +{ + // In gcc headers, lots of built-ins are referenced that clang does not understand. + // Therefore, prevent the inclusion of the header that references them. Of course, this + // will break if code actually requires stuff from there, but that should be the less common + // case. + + const Core::Id type = m_projectPart.toolchainType; + if (type == ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID + || type == ProjectExplorer::Constants::GCC_TOOLCHAIN_TYPEID) { + addDefine("#define _X86INTRIN_H_INCLUDED"); + } +} + static QByteArray toMsCompatibilityVersionFormat(const QByteArray &mscFullVer) { return mscFullVer.left(2) diff --git a/src/plugins/cpptools/compileroptionsbuilder.h b/src/plugins/cpptools/compileroptionsbuilder.h index e1ec557d835..4cae4bb353d 100644 --- a/src/plugins/cpptools/compileroptionsbuilder.h +++ b/src/plugins/cpptools/compileroptionsbuilder.h @@ -53,6 +53,8 @@ public: virtual void addLanguageOption(ProjectFile::Kind fileKind); virtual void addOptionsForLanguage(bool checkForBorlandExtensions = true); + void addDefineToAvoidIncludingGccOrMinGwIntrinsics(); + void addMsvcCompatibilityVersion(); void undefineCppLanguageFeatureMacrosForMsvc2015();