forked from qt-creator/qt-creator
Clang: enable clang tidy and clazy in code model
Set QTC_CLANG_PLUGINS_LOAD env variable to get diagnostics that come from libclang plugins. This functionality works after the patch is applied to clang repository and clang is properly built with it. Task-number: QTCREATORBUG-15157 Change-Id: Iefeee4dd115f3f43ddc6ed79452a1135e653def6 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
134
dist/clang/patches/QTCREATORBUG-15157_Link-with-clazy.patch
vendored
Normal file
134
dist/clang/patches/QTCREATORBUG-15157_Link-with-clazy.patch
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
diff --git a/lib/Transforms/CMakeLists.txt b/lib/Transforms/CMakeLists.txt
|
||||
index 67bdeb27212..7fcddb15904 100644
|
||||
--- a/lib/Transforms/CMakeLists.txt
|
||||
+++ b/lib/Transforms/CMakeLists.txt
|
||||
@@ -4,6 +4,5 @@ add_subdirectory(InstCombine)
|
||||
add_subdirectory(Scalar)
|
||||
add_subdirectory(IPO)
|
||||
add_subdirectory(Vectorize)
|
||||
-add_subdirectory(Hello)
|
||||
add_subdirectory(ObjCARC)
|
||||
add_subdirectory(Coroutines)
|
||||
|
||||
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
|
||||
index 124f0c72fd7..fdff2ffe6d4 100644
|
||||
--- a/test/CMakeLists.txt
|
||||
+++ b/test/CMakeLists.txt
|
||||
@@ -29,7 +29,6 @@ endif()
|
||||
set(LLVM_TEST_DEPENDS
|
||||
BugpointPasses
|
||||
FileCheck
|
||||
- LLVMHello
|
||||
UnitTests
|
||||
bugpoint
|
||||
count
|
||||
diff --git a/tools/clang/tools/libclang/CMakeLists.txt b/tools/clang/tools/libclang/CMakeLists.txt
|
||||
index 2dd6703076..2ef48266ac 100644
|
||||
--- a/tools/clang/tools/libclang/CMakeLists.txt
|
||||
+++ b/tools/clang/tools/libclang/CMakeLists.txt
|
||||
@@ -19,6 +19,7 @@ set(SOURCES
|
||||
CXString.cpp
|
||||
CXType.cpp
|
||||
Indexing.cpp
|
||||
+ LinkClazy.cpp
|
||||
|
||||
ADDITIONAL_HEADERS
|
||||
CIndexDiagnostic.h
|
||||
@@ -53,6 +54,14 @@ if (TARGET clangTidyPlugin)
|
||||
list(APPEND LIBS clangIncludeFixerPlugin)
|
||||
endif ()
|
||||
|
||||
+option(CLANG_ENABLE_CLAZY "Build libclang with clazy" OFF)
|
||||
+
|
||||
+if (CLANG_ENABLE_CLAZY)
|
||||
+ add_definitions(-DENABLE_CLAZY)
|
||||
+ link_directories(${CMAKE_INSTALL_PREFIX}/lib)
|
||||
+ list(APPEND LIBS ClangLazy clangRewriteFrontend)
|
||||
+endif()
|
||||
+
|
||||
find_library(DL_LIBRARY_PATH dl)
|
||||
if (DL_LIBRARY_PATH)
|
||||
list(APPEND LIBS dl)
|
||||
diff --git a/tools/clang/tools/libclang/LinkClazy.cpp b/tools/clang/tools/libclang/LinkClazy.cpp
|
||||
new file mode 100644
|
||||
--- /dev/null
|
||||
+++ b/tools/clang/tools/libclang/LinkClazy.cpp
|
||||
@@ -0,0 +1,78 @@
|
||||
+#ifdef ENABLE_CLAZY
|
||||
+extern volatile int ClazyPluginAnchorSource;
|
||||
+static int ClazyPluginAnchorDestination = ClazyPluginAnchorSource;
|
||||
+
|
||||
+#define REGISTER_CHECK_WITH_FLAGS(CHECK_NAME, CLASS_NAME, LEVEL, OPTIONS) \
|
||||
+ extern volatile int ClazyAnchor_##CLASS_NAME; \
|
||||
+ volatile int ClazyAnchorDestination_##CLASS_NAME = ClazyAnchor_##CLASS_NAME;
|
||||
+#define REGISTER_CHECK(CHECK_NAME, CLASS_NAME, LEVEL) \
|
||||
+ extern volatile int ClazyAnchor_##CLASS_NAME; \
|
||||
+ static int ClazyAnchorDestination_##CLASS_NAME = ClazyAnchor_##CLASS_NAME;
|
||||
+
|
||||
+REGISTER_CHECK("inefficient-qlist", InefficientQList, HiddenCheckLevel)
|
||||
+REGISTER_CHECK("isempty-vs-count", IsEmptyVSCount, HiddenCheckLevel)
|
||||
+REGISTER_CHECK(s_checkName, Qt4_QStringFromArray, HiddenCheckLevel)
|
||||
+REGISTER_CHECK("tr-non-literal", TrNonLiteral, HiddenCheckLevel)
|
||||
+REGISTER_CHECK("connect-non-signal", ConnectNonSignal, CheckLevel0)
|
||||
+REGISTER_CHECK("connect-not-normalized", ConnectNotNormalized, CheckLevel0)
|
||||
+REGISTER_CHECK("container-anti-pattern", ContainerAntiPattern, CheckLevel0)
|
||||
+REGISTER_CHECK("lambda-in-connect", LambdaInConnect, CheckLevel0)
|
||||
+REGISTER_CHECK("mutable-container-key", MutableContainerKey, CheckLevel0)
|
||||
+REGISTER_CHECK("qcolor-from-literal", QColorFromLiteral, CheckLevel0)
|
||||
+REGISTER_CHECK(s_checkName, QDateTimeUtc, CheckLevel0)
|
||||
+REGISTER_CHECK_WITH_FLAGS("qenums", Qenums, CheckLevel0, RegisteredCheck::Option_Qt4Incompatible)
|
||||
+REGISTER_CHECK("qfileinfo-exists", QFileInfoExists, CheckLevel0)
|
||||
+REGISTER_CHECK_WITH_FLAGS(s_checkName, QGetEnv, CheckLevel0, RegisteredCheck::Option_Qt4Incompatible)
|
||||
+REGISTER_CHECK("qmap-with-pointer-key", QMapWithPointerKey, CheckLevel0)
|
||||
+REGISTER_CHECK("qstring-insensitive-allocation", QStringInsensitiveAllocation, CheckLevel0)
|
||||
+REGISTER_CHECK("qstring-arg", StringArg, CheckLevel0)
|
||||
+REGISTER_CHECK(s_checkName, StringRefCandidates, CheckLevel0)
|
||||
+REGISTER_CHECK("qt-macros", QtMacros, CheckLevel0)
|
||||
+REGISTER_CHECK("qvariant-template-instantiation", QVariantTemplateInstantiation, CheckLevel0)
|
||||
+REGISTER_CHECK("strict-iterators", StrictIterators, CheckLevel0)
|
||||
+REGISTER_CHECK("temporary-iterator", TemporaryIterator, CheckLevel0)
|
||||
+REGISTER_CHECK("unused-non-trivial-variable", UnusedNonTrivialVariable, CheckLevel0)
|
||||
+REGISTER_CHECK("writing-to-temporary", WritingToTemporary, CheckLevel0)
|
||||
+REGISTER_CHECK("wrong-qglobalstatic", WrongQGlobalStatic, CheckLevel0)
|
||||
+REGISTER_CHECK(s_checkName, AutoUnexpectedQStringBuilder, CheckLevel1)
|
||||
+REGISTER_CHECK("child-event-qobject-cast", ChildEvent_qobject_cast, CheckLevel1)
|
||||
+REGISTER_CHECK("connect-3arg-lambda", Connect3argLambda, CheckLevel1)
|
||||
+REGISTER_CHECK("const-signal-or-slot", ConstSignalOrSlot, CheckLevel1)
|
||||
+REGISTER_CHECK("ctor-missing-parent-argument", CtorMissingParentArgument, CheckLevel2)
|
||||
+REGISTER_CHECK("detaching-temporary", DetachingTemporary, CheckLevel1)
|
||||
+REGISTER_CHECK("foreach", Foreach, CheckLevel1)
|
||||
+REGISTER_CHECK("incorrect-emit", IncorrectEmit, CheckLevel1)
|
||||
+REGISTER_CHECK("inefficient-qlist-soft", InefficientQListSoft, CheckLevel1)
|
||||
+REGISTER_CHECK("install-event-filter", InstallEventFilter, CheckLevel1)
|
||||
+REGISTER_CHECK("non-pod-global-static", NonPodStatic, CheckLevel1)
|
||||
+REGISTER_CHECK("overridden-signal", OverriddenSignal, CheckLevel1)
|
||||
+REGISTER_CHECK("post-event", PostEvent, CheckLevel1)
|
||||
+REGISTER_CHECK("qdeleteall", QDeleteAll, CheckLevel1)
|
||||
+REGISTER_CHECK("qhash-namespace", qhash_namespace, CheckLevel1)
|
||||
+REGISTER_CHECK("qlatin1string-non-ascii", QLatin1StringNonAscii, CheckLevel1)
|
||||
+REGISTER_CHECK("qproperty-without-notify", QPropertyWithoutNotify, CheckLevel1)
|
||||
+REGISTER_CHECK("qstring-left", QStringLeft, CheckLevel1)
|
||||
+REGISTER_CHECK("range-loop", RangeLoop, CheckLevel1)
|
||||
+REGISTER_CHECK("returning-data-from-temporary", ReturningDataFromTemporary, CheckLevel1)
|
||||
+REGISTER_CHECK("rule-of-two-soft", RuleOfTwoSoft, CheckLevel1)
|
||||
+REGISTER_CHECK("virtual-signal", VirtualSignal, CheckLevel1)
|
||||
+REGISTER_CHECK("base-class-event", BaseClassEvent, CheckLevel2)
|
||||
+REGISTER_CHECK("container-inside-loop", ContainerInsideLoop, CheckLevel2)
|
||||
+REGISTER_CHECK("copyable-polymorphic", CopyablePolymorphic, CheckLevel2)
|
||||
+REGISTER_CHECK(s_checkName, FunctionArgsByRef, CheckLevel2)
|
||||
+REGISTER_CHECK("function-args-by-value", FunctionArgsByValue, CheckLevel2)
|
||||
+REGISTER_CHECK("global-const-char-pointer", GlobalConstCharPointer, CheckLevel2)
|
||||
+REGISTER_CHECK("implicit-casts", ImplicitCasts, CheckLevel2)
|
||||
+REGISTER_CHECK("missing-qobject-macro", MissingQ_OBJECT, CheckLevel2)
|
||||
+REGISTER_CHECK("missing-typeinfo", MissingTypeinfo, CheckLevel2)
|
||||
+REGISTER_CHECK_WITH_FLAGS(s_checkName, OldStyleConnect, CheckLevel2, RegisteredCheck::Option_Qt4Incompatible)
|
||||
+REGISTER_CHECK_WITH_FLAGS(s_checkName, QStringAllocations, CheckLevel2, RegisteredCheck::Option_Qt4Incompatible)
|
||||
+REGISTER_CHECK("reserve-candidates", ReserveCandidates, CheckLevel2)
|
||||
+REGISTER_CHECK("returning-void-expression", ReturningVoidExpression, CheckLevel2)
|
||||
+REGISTER_CHECK("rule-of-three", RuleOfThree, CheckLevel2)
|
||||
+REGISTER_CHECK("virtual-call-ctor", VirtualCallsFromCTOR, CheckLevel2)
|
||||
+REGISTER_CHECK("assert-with-side-effects", AssertWithSideEffects, CheckLevel3)
|
||||
+REGISTER_CHECK("detaching-member", DetachingMember, CheckLevel3)
|
||||
+REGISTER_CHECK("bogus-dynamic-cast", BogusDynamicCast, CheckLevel3)
|
||||
+REGISTER_CHECK("thread-with-slots", ThreadWithSlots, CheckLevel3)
|
||||
+#endif
|
||||
7
dist/clang/patches/README
vendored
7
dist/clang/patches/README
vendored
@@ -37,3 +37,10 @@ QTCREATORBUG-15449_Fix-files-lock-on-Windows.patch
|
||||
|
||||
Significantly reduces problems when saving a header file on Windows.
|
||||
|
||||
QTCREATORBUG-15157_Link-with-clazy.patch
|
||||
|
||||
https://bugreports.qt.io/browse/QTCREATORBUG-15157
|
||||
|
||||
Introduces the flag CLANG_ENABLE_CLAZY to link libclang with Clazy and
|
||||
forces link for Clazy checks and plugin registry entry.
|
||||
|
||||
|
||||
@@ -79,6 +79,12 @@ static QString creatorResourcePath()
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool loadClangPlugins()
|
||||
{
|
||||
static bool load = qEnvironmentVariableIntValue("QTC_CLANG_PLUGINS_LOAD");
|
||||
return load;
|
||||
}
|
||||
|
||||
class LibClangOptionsBuilder final : public CompilerOptionsBuilder
|
||||
{
|
||||
public:
|
||||
@@ -96,6 +102,10 @@ public:
|
||||
void addExtraOptions() final
|
||||
{
|
||||
addDummyUiHeaderOnDiskIncludePath();
|
||||
if (loadClangPlugins()) {
|
||||
addTidyPlugin();
|
||||
addClazyPlugin();
|
||||
}
|
||||
add("-fmessage-length=0");
|
||||
add("-fdiagnostics-show-note-include-stack");
|
||||
add("-fmacro-backtrace-limit=0");
|
||||
@@ -123,6 +133,26 @@ private:
|
||||
if (!path.isEmpty())
|
||||
add(includeDirOption() + QDir::toNativeSeparators(path));
|
||||
}
|
||||
|
||||
void addClazyPlugin()
|
||||
{
|
||||
add("-Xclang");
|
||||
add("-add-plugin");
|
||||
add("-Xclang");
|
||||
add("clang-lazy");
|
||||
}
|
||||
|
||||
void addTidyPlugin()
|
||||
{
|
||||
add("-Xclang");
|
||||
add("-add-plugin");
|
||||
add("-Xclang");
|
||||
add("clang-tidy");
|
||||
add("-Xclang");
|
||||
add("-plugin-arg-clang-tidy");
|
||||
add("-Xclang");
|
||||
add("-checks='-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming'");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user