juliehockett updated this revision to Diff 129647.
juliehockett marked 3 inline comments as done.
juliehockett added a comment.

Fixing comments


https://reviews.llvm.org/D41963

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/ThreadLocalCheck.cpp
  clang-tidy/fuchsia/ThreadLocalCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-thread-local.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-thread-local.cpp

Index: test/clang-tidy/fuchsia-thread-local.cpp
===================================================================
--- /dev/null
+++ test/clang-tidy/fuchsia-thread-local.cpp
@@ -0,0 +1,14 @@
+// RUN: %check_clang_tidy %s fuchsia-thread-local %t
+
+int main() {
+  thread_local int foo;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: thread local storage is disallowed
+  // CHECK-NEXT:  thread_local int foo;
+
+  extern thread_local int bar;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: thread local storage is disallowed
+  // CHECK-NEXT:  extern thread_local int bar;
+  int baz;
+  
+  return 0;
+}
Index: docs/clang-tidy/checks/list.rst
===================================================================
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -71,6 +71,7 @@
    fuchsia-default-arguments
    fuchsia-overloaded-operator
    fuchsia-statically-constructed-objects
+   fuchsia-thread-local
    fuchsia-virtual-inheritance
    google-build-explicit-make-pair
    google-build-namespaces
Index: docs/clang-tidy/checks/fuchsia-thread-local.rst
===================================================================
--- /dev/null
+++ docs/clang-tidy/checks/fuchsia-thread-local.rst
@@ -0,0 +1,15 @@
+.. title:: clang-tidy - fuchsia-thread-local
+
+fuchsia-thread-local
+====================
+
+Warns if thread storage duration is used.
+
+For example, using ``thread_local`` or ``extern thread_local`` is not allowed:
+
+.. code-block:: c++
+
+  thread_local int foo;           // Warning
+  extern thread_local int bar;    // Warning
+
+See the features disallowed in Fuchsia at https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md
Index: docs/ReleaseNotes.rst
===================================================================
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -64,6 +64,11 @@
   object is statically initialized with a ``constexpr`` constructor or has no 
   explicit constructor.
 
+- New `fuchsia-thread-local
+  <http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-thread-local.html>`_ check
+
+  Warns if thread storage duration is used.
+
 Improvements to include-fixer
 -----------------------------
 
Index: clang-tidy/fuchsia/ThreadLocalCheck.h
===================================================================
--- /dev/null
+++ clang-tidy/fuchsia/ThreadLocalCheck.h
@@ -0,0 +1,35 @@
+//===--- ThreadLocalCheck.h - clang-tidy-------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_THREAD_LOCAL_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_THREAD_LOCAL_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// Thread storage duration is disallowed.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-thread-local.html
+class ThreadLocalCheck : public ClangTidyCheck {
+public:
+  ThreadLocalCheck(StringRef Name, ClangTidyContext *Context)
+      : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_THREAD_LOCAL_H
Index: clang-tidy/fuchsia/ThreadLocalCheck.cpp
===================================================================
--- /dev/null
+++ clang-tidy/fuchsia/ThreadLocalCheck.cpp
@@ -0,0 +1,32 @@
+//===--- ThreadLocalCheck.cpp - clang-tidy---------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ThreadLocalCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+void ThreadLocalCheck::registerMatchers(MatchFinder *Finder) {
+  // Using thread storage duration is disallowed.
+  Finder->addMatcher(varDecl(hasThreadStorageDuration()).bind("decl"), this);
+}
+
+void ThreadLocalCheck::check(const MatchFinder::MatchResult &Result) {
+  if (const auto *D = Result.Nodes.getNodeAs<VarDecl>("decl"))
+    diag(D->getLocStart(), "thread local storage is disallowed");
+}
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang
Index: clang-tidy/fuchsia/FuchsiaTidyModule.cpp
===================================================================
--- clang-tidy/fuchsia/FuchsiaTidyModule.cpp
+++ clang-tidy/fuchsia/FuchsiaTidyModule.cpp
@@ -13,6 +13,7 @@
 #include "DefaultArgumentsCheck.h"
 #include "OverloadedOperatorCheck.h"
 #include "StaticallyConstructedObjectsCheck.h"
+#include "ThreadLocalCheck.h"
 #include "VirtualInheritanceCheck.h"
 
 using namespace clang::ast_matchers;
@@ -31,6 +32,8 @@
         "fuchsia-overloaded-operator");
     CheckFactories.registerCheck<StaticallyConstructedObjectsCheck>(
         "fuchsia-statically-constructed-objects");
+    CheckFactories.registerCheck<ThreadLocalCheck>(
+        "fuchsia-thread-local");
     CheckFactories.registerCheck<VirtualInheritanceCheck>(
         "fuchsia-virtual-inheritance");
   }
Index: clang-tidy/fuchsia/CMakeLists.txt
===================================================================
--- clang-tidy/fuchsia/CMakeLists.txt
+++ clang-tidy/fuchsia/CMakeLists.txt
@@ -3,6 +3,7 @@
 add_clang_library(clangTidyFuchsiaModule
   DefaultArgumentsCheck.cpp
   FuchsiaTidyModule.cpp
+  ThreadLocalCheck.cpp
   OverloadedOperatorCheck.cpp
   StaticallyConstructedObjectsCheck.cpp
   VirtualInheritanceCheck.cpp
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to