From 6884ab080e28699ca662878d7083cd84b9f206d4 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Mon, 10 Oct 2016 17:31:19 +0200 Subject: [PATCH] ClangStaticAnalyzer: Fix path for intrinsics for clang toolchains Ignore the include path for intrinsics coming from the toolchain. The clang static analyzer comes with its own intrinsics and does not cope well with intrinsics from other clang versions. Move the relevant implementation from LibClangOptionsBuilder into the base class so that ClangStaticAnalyzer profits from this, too. Task-number: QTCREATORBUG-17102 Change-Id: Id9a28ddebb889c862939332dce888a80b3bb7e63 Reviewed-by: Christian Kandeler --- src/plugins/clangcodemodel/clangutils.cpp | 17 +++++------------ .../refactoringcompileroptionsbuilder.cpp | 16 +++++----------- .../refactoringcompileroptionsbuilder.h | 1 - src/plugins/cpptools/compileroptionsbuilder.cpp | 11 ++++++++++- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/plugins/clangcodemodel/clangutils.cpp b/src/plugins/clangcodemodel/clangutils.cpp index 5ef7b1648d6..c18f1900ba3 100644 --- a/src/plugins/clangcodemodel/clangutils.cpp +++ b/src/plugins/clangcodemodel/clangutils.cpp @@ -38,7 +38,6 @@ #include #include -#include #include using namespace ClangCodeModel; @@ -118,18 +117,12 @@ private: bool excludeHeaderPath(const QString &path) const override { - if (path.contains(QLatin1String("lib/gcc/i686-apple-darwin"))) - return true; + if (m_projectPart.toolchainType == ProjectExplorer::Constants::CLANG_TOOLCHAIN_TYPEID) { + if (path.contains(QLatin1String("lib/gcc/i686-apple-darwin"))) + return true; + } - // We already provide a custom clang include path matching the used libclang version, - // so better ignore the clang include paths from the system as this might lead to an - // unfavorable order with regard to include_next. - static QRegularExpression clangIncludeDir( - QLatin1String("\\A.*/lib/clang/\\d+\\.\\d+(\\.\\d+)?/include\\z")); - if (clangIncludeDir.match(path).hasMatch()) - return true; - - return false; + return CompilerOptionsBuilder::excludeHeaderPath(path); } void addPredefinedMacrosAndHeaderPathsOptions() diff --git a/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.cpp b/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.cpp index 6546e9b9500..372cf1af150 100644 --- a/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.cpp +++ b/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.cpp @@ -56,18 +56,12 @@ RefactoringCompilerOptionsBuilder::RefactoringCompilerOptionsBuilder(CppTools::P bool RefactoringCompilerOptionsBuilder::excludeHeaderPath(const QString &path) const { - if (path.contains(QLatin1String("lib/gcc/i686-apple-darwin"))) - return true; + if (m_projectPart.toolchainType == ProjectExplorer::Constants::CLANG_TOOLCHAIN_TYPEID) { + if (path.contains(QLatin1String("lib/gcc/i686-apple-darwin"))) + return true; + } - // We already provide a custom clang include path matching the used libclang version, - // so better ignore the clang include paths from the system as this might lead to an - // unfavorable order with regard to include_next. - static QRegularExpression clangIncludeDir( - QLatin1String("\\A.*/lib/clang/\\d+\\.\\d+(\\.\\d+)?/include\\z")); - if (clangIncludeDir.match(path).hasMatch()) - return true; - - return false; + return CompilerOptionsBuilder::excludeHeaderPath(path); } void RefactoringCompilerOptionsBuilder::addPredefinedMacrosAndHeaderPathsOptions() diff --git a/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.h b/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.h index f0f0dcc016d..9a11573e8d0 100644 --- a/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.h +++ b/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.h @@ -34,7 +34,6 @@ #include #include -#include namespace ClangRefactoring { diff --git a/src/plugins/cpptools/compileroptionsbuilder.cpp b/src/plugins/cpptools/compileroptionsbuilder.cpp index a5bf1ad0b65..c529e96b45d 100644 --- a/src/plugins/cpptools/compileroptionsbuilder.cpp +++ b/src/plugins/cpptools/compileroptionsbuilder.cpp @@ -28,6 +28,7 @@ #include #include +#include namespace CppTools { @@ -393,7 +394,15 @@ bool CompilerOptionsBuilder::excludeDefineLine(const QByteArray &defineLine) con bool CompilerOptionsBuilder::excludeHeaderPath(const QString &headerPath) const { - Q_UNUSED(headerPath); + // A clang tool chain might have another version and passing in the + // intrinsics path from that version will lead to errors (unknown + // intrinsics, unfavorable order with regard to include_next). + if (m_projectPart.toolchainType == ProjectExplorer::Constants::CLANG_TOOLCHAIN_TYPEID) { + static QRegularExpression clangIncludeDir( + QLatin1String("\\A.*/lib/clang/\\d+\\.\\d+(\\.\\d+)?/include\\z")); + return clangIncludeDir.match(headerPath).hasMatch(); + } + return false; }