Bug 1486410 - Bug 1466427 - Enable new clang-tidy 7.0 checks. r=andi
☠☠ backed out by 72c2fc2d0ab1 ☠ ☠
authorJan Keromnes <janx@linux.com>
Mon, 27 Aug 2018 17:56:03 +0000
changeset 481941 f9d93a20e6d6c5c5fca0fa3309d96b3f2328714b
parent 481940 126368a5c3ec8880f748a8bb91844048f67922b6
child 481942 bcf51e940502c1d622857fc8632454b89ed7374a
push id232
push userfmarier@mozilla.com
push dateWed, 05 Sep 2018 20:45:54 +0000
reviewersandi
bugs1486410, 1466427
milestone63.0a1
Bug 1486410 - Bug 1466427 - Enable new clang-tidy 7.0 checks. r=andi Differential Revision: https://phabricator.services.mozilla.com/D4210
tools/clang-tidy/config.yaml
tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.cpp
tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.json
tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.cpp
tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.json
tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.cpp
tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.json
tools/clang-tidy/test/performance-implicit-conversion-in-loop.cpp
tools/clang-tidy/test/performance-implicit-conversion-in-loop.json
tools/clang-tidy/test/performance-inefficient-algorithm.cpp
tools/clang-tidy/test/performance-inefficient-algorithm.json
tools/clang-tidy/test/performance-move-const-arg.cpp
tools/clang-tidy/test/performance-move-const-arg.json
tools/clang-tidy/test/performance-move-constructor-init.cpp
tools/clang-tidy/test/performance-move-constructor-init.json
tools/clang-tidy/test/performance-noexcept-move-constructor.cpp
tools/clang-tidy/test/performance-noexcept-move-constructor.json
tools/clang-tidy/test/readability-static-accessed-through-instance.cpp
tools/clang-tidy/test/readability-static-accessed-through-instance.json
tools/clang-tidy/test/structures.h
--- a/tools/clang-tidy/config.yaml
+++ b/tools/clang-tidy/config.yaml
@@ -38,16 +38,22 @@ clang_checkers:
   - name: clang-analyzer-cplusplus.NewDelete
     publish: !!bool yes
   - name: clang-analyzer-cplusplus.NewDeleteLeaks
     publish: !!bool yes
   - name: clang-analyzer-deadcode.DeadStores
     publish: !!bool yes
   - name: clang-analyzer-security.FloatLoopCounter
     publish: !!bool yes
+  - name: clang-analyzer-security.insecureAPI.bcmp
+    publish: !!bool yes
+  - name: clang-analyzer-security.insecureAPI.bcopy
+    publish: !!bool yes
+  - name: clang-analyzer-security.insecureAPI.bzero
+    publish: !!bool yes
   - name: clang-analyzer-security.insecureAPI.getpw
     publish: !!bool yes
   # We don't add clang-analyzer-security.insecureAPI.gets here; it's deprecated.
   - name: clang-analyzer-security.insecureAPI.mkstemp
     publish: !!bool yes
   - name: clang-analyzer-security.insecureAPI.mktemp
     publish: !!bool yes
   - name: clang-analyzer-security.insecureAPI.rand
@@ -96,23 +102,30 @@ clang_checkers:
     # Too noisy because of the way how we implement NS_IMETHOD. See Bug 1420366.
     publish: !!bool no
   - name: mozilla-*
     publish: !!bool yes
   - name: performance-faster-string-find
     publish: !!bool yes
   - name: performance-for-range-copy
     publish: !!bool yes
-  # Only available from clang tidy 6.0. We are currently using 5.0
-  # - name: performance-implicit-conversion-in-loop
-  #   publish: !!bool yes
+  - name: performance-implicit-conversion-in-loop
+    publish: !!bool yes
+  - name: performance-inefficient-algorithm
+    publish: !!bool yes
   - name: performance-inefficient-string-concatenation
     publish: !!bool yes
   - name: performance-inefficient-vector-operation
     publish: !!bool yes
+  - name: performance-move-const-arg
+    publish: !!bool yes
+  - name: performance-move-constructor-init
+    publish: !!bool yes
+  - name: performance-noexcept-move-constructor
+    publish: !!bool yes
   - name: performance-type-promotion-in-math-fn
     publish: !!bool yes
   - name: performance-unnecessary-copy-initialization
     publish: !!bool yes
   - name: performance-unnecessary-value-param
     publish: !!bool yes
   - name: readability-container-size-empty
     publish: !!bool yes
@@ -125,14 +138,13 @@ clang_checkers:
   - name: readability-redundant-smartptr-get
     publish: !!bool no
   - name: readability-redundant-string-cstr
     publish: !!bool yes
   - name: readability-redundant-string-init
     publish: !!bool yes
   - name: readability-uniqueptr-delete-release
     publish: !!bool yes
-# Only available from clang tidy 6.0. We are currently using 5.0
-# - name: readability-static-accessed-through-instance
-#   publish: !!bool yes
+  - name: readability-static-accessed-through-instance
+    publish: !!bool yes
 
 # Third party files from mozilla-central
 third_party: tools/rewriting/ThirdPartyPaths.txt
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.cpp
@@ -0,0 +1,6 @@
+#include "structures.h"
+
+int test_bcmp(void *a, void *b, size_t n) {
+  return bcmp(a, b, n);
+}
+
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.json
@@ -0,0 +1,1 @@
+"[[\"warning\", \"The bcmp() function is obsoleted by memcmp()\", \"clang-analyzer-security.insecureAPI.bcmp\"]]"
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.cpp
@@ -0,0 +1,6 @@
+#include "structures.h"
+
+void test_bcopy(void *a, void *b, size_t n) {
+  bcopy(a, b, n);
+}
+
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.json
@@ -0,0 +1,1 @@
+"[[\"warning\", \"The bcopy() function is obsoleted by memcpy() or memmove()\", \"clang-analyzer-security.insecureAPI.bcopy\"]]"
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.cpp
@@ -0,0 +1,6 @@
+#include "structures.h"
+
+void test_bzero(void *a, size_t n) {
+  bzero(a, n);
+}
+
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.json
@@ -0,0 +1,1 @@
+"[[\"warning\", \"The bzero() function is obsoleted by memset()\", \"clang-analyzer-security.insecureAPI.bzero\"]]"
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/performance-implicit-conversion-in-loop.cpp
@@ -0,0 +1,43 @@
+// Iterator returning by value.
+template <typename T>
+struct Iterator {
+  void operator++();
+  T operator*();
+  bool operator!=(const Iterator& other);
+};
+
+// The template argument is an iterator type, and a view is an object you can
+// run a for loop on.
+template <typename T>
+struct View {
+  T begin();
+  T end();
+};
+
+// With this class, the implicit conversion is a call to the (implicit)
+// constructor of the class.
+template <typename T>
+class ImplicitWrapper {
+ public:
+  // Implicit!
+  ImplicitWrapper(const T& t);
+};
+
+template <typename T>
+class OperatorWrapper {
+ public:
+  OperatorWrapper() = delete;
+};
+
+struct SimpleClass {
+  int foo;
+  operator OperatorWrapper<SimpleClass>();
+};
+
+typedef View<Iterator<SimpleClass>> SimpleView;
+
+void ImplicitSimpleClassIterator() {
+  for (const ImplicitWrapper<SimpleClass>& foo : SimpleView()) {}
+  for (const ImplicitWrapper<SimpleClass> foo : SimpleView()) {}
+  for (ImplicitWrapper<SimpleClass> foo : SimpleView()) {}
+}
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/performance-implicit-conversion-in-loop.json
@@ -0,0 +1,1 @@
+"[[\"warning\", \"the type of the loop variable 'foo' is different from the one returned by the iterator and generates an implicit conversion; you can either change the type to the matching one ('const SimpleClass &' but 'const auto&' is always a valid option) or remove the reference to make it explicit that you are creating a new value\", \"performance-implicit-conversion-in-loop\"]]"
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/performance-inefficient-algorithm.cpp
@@ -0,0 +1,31 @@
+namespace std {
+template <typename T> struct less {
+  bool operator()(const T &lhs, const T &rhs) { return lhs < rhs; }
+};
+
+template <typename T> struct greater {
+  bool operator()(const T &lhs, const T &rhs) { return lhs > rhs; }
+};
+
+struct iterator_type {};
+
+template <typename K, typename Cmp = less<K>> struct set {
+  typedef iterator_type iterator;
+  iterator find(const K &k);
+  unsigned count(const K &k);
+
+  iterator begin();
+  iterator end();
+  iterator begin() const;
+  iterator end() const;
+};
+
+template <typename FwIt, typename K>
+FwIt find(FwIt, FwIt end, const K &) { return end; }
+}
+
+template <typename T> void f(const T &t) {
+  std::set<int> s;
+  find(s.begin(), s.end(), 46);
+}
+
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/performance-inefficient-algorithm.json
@@ -0,0 +1,1 @@
+"[[\"warning\", \"this STL algorithm call should be replaced with a container method\", \"performance-inefficient-algorithm\"]]"
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/performance-move-const-arg.cpp
@@ -0,0 +1,22 @@
+namespace std {
+template <typename _Tp>
+struct remove_reference {
+  typedef _Tp type;
+};
+
+template <typename _Tp>
+constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) {
+  return static_cast<typename std::remove_reference<_Tp>::type &&>(__t);
+}
+} // namespace std
+
+struct TriviallyCopyable {
+  int i;
+};
+
+void f(TriviallyCopyable) {}
+
+void g() {
+  TriviallyCopyable obj;
+  f(std::move(obj));
+}
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/performance-move-const-arg.json
@@ -0,0 +1,1 @@
+"[[\"warning\", \"std::move of the variable 'obj' of the trivially-copyable type 'TriviallyCopyable' has no effect; remove std::move()\", \"performance-move-const-arg\"]]"
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/performance-move-constructor-init.cpp
@@ -0,0 +1,11 @@
+struct B {
+  B() {}
+  B(const B&) {}
+  B(B &&) {}
+};
+
+struct D : B {
+  D() : B() {}
+  D(const D &RHS) : B(RHS) {}
+  D(D &&RHS) : B(RHS) {}
+};
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/performance-move-constructor-init.json
@@ -0,0 +1,1 @@
+"[[\"warning\", \"move constructor initializes base class by calling a copy constructor\", \"performance-move-constructor-init\"]]"
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/performance-noexcept-move-constructor.cpp
@@ -0,0 +1,4 @@
+class A {
+  A(A &&);
+  A &operator=(A &&);
+};
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/performance-noexcept-move-constructor.json
@@ -0,0 +1,1 @@
+"[[\"warning\", \"move constructors should be marked noexcept\", \"performance-noexcept-move-constructor\"], [\"warning\", \"move assignment operators should be marked noexcept\", \"performance-noexcept-move-constructor\"]]"
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/readability-static-accessed-through-instance.cpp
@@ -0,0 +1,11 @@
+struct C {
+  static int x;
+};
+
+int C::x = 0;
+
+// Expressions with side effects
+C &f(int, int, int, int);
+void g() {
+  f(1, 2, 3, 4).x;
+}
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/readability-static-accessed-through-instance.json
@@ -0,0 +1,1 @@
+"[[\"warning\", \"static member accessed through instance\", \"readability-static-accessed-through-instance\"]]"
\ No newline at end of file
--- a/tools/clang-tidy/test/structures.h
+++ b/tools/clang-tidy/test/structures.h
@@ -76,16 +76,20 @@ class bind_rt {};
 
 template <class Fp, class... Arguments>
 bind_rt<Fp, Arguments...> bind(Fp &&, Arguments &&...);
 }
 
 typedef unsigned int uid_t;
 typedef unsigned int pid_t;
 
+int bcmp(void *, void *, size_t);
+void bcopy(void *, void *, size_t);
+void bzero(void *, size_t);
+
 int getpw(uid_t uid, char *buf);
 int setuid(uid_t uid);
 
 int mkstemp(char *tmpl);
 char *mktemp(char *tmpl);
 
 pid_t vfork(void);