[PATCH] D67567: New ClangTidy checks to warn about misusing dispatch_once_t

Michael Wyman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 13 12:02:18 PDT 2019


mwyman created this revision.
mwyman added reviewers: benhamilton, hokein, stephanemoore.
Herald added subscribers: cfe-commits, mgorny.
Herald added a project: clang.

Adds two new ClangTidy checks:

- misc-dispatch-once-assignment: warns about assignment to a dispatch_once_t variable. In code reviews I've encountered enough attempts to "reset" a dispatch_once.
- misc-dispatch-once-nonstatic: warns about dispatch_once_t variables not in static or global storage. This catches a missing static for local variables in e.g. singleton initialization behavior, and also warns on storing dispatch_once_t values in Objective-C instance variables. C/C++ struct/class instances may potentially live in static/global storage, and are ignored for this check.

The osx.API static analysis checker can find the non-static storage use of dispatch_once_t; I thought it useful to also catch these issues in clang-tidy when possible.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D67567

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/DispatchOnceAssignmentCheck.cpp
  clang-tools-extra/clang-tidy/misc/DispatchOnceAssignmentCheck.h
  clang-tools-extra/clang-tidy/misc/DispatchOnceNonstaticCheck.cpp
  clang-tools-extra/clang-tidy/misc/DispatchOnceNonstaticCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-dispatch-once-assignment.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-dispatch-once-nonstatic.rst
  clang-tools-extra/test/clang-tidy/misc-dispatch-once-assignment.cpp
  clang-tools-extra/test/clang-tidy/misc-dispatch-once-nonstatic.mm

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67567.220149.patch
Type: text/x-patch
Size: 14711 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190913/e02dfa8e/attachment.bin>


More information about the cfe-commits mailing list