[PATCH] D90944: [clang-tidy] implement misc-mt-unsafe

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 16 04:39:08 PST 2020


lebedev.ri added a comment.

`Libc` option name doesn't really make sense to me, maybe `FunctionSet` would fit better.



================
Comment at: clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.cpp:32-33
+
+// Initial list was extracted from gcc documentation
+static const StringRef glibcFunctions[] = {
+    "::argp_error",
----------------
I would expect this can be outside of all the namespaces right after `using namespace clang::ast_matchers;`


================
Comment at: clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.cpp:287-288
+
+static ast_matchers::internal::Matcher<clang::NamedDecl>
+hasAnyMtUnsafeNames(MtUnsafeCheck::LibcType libc) {
+  switch (libc) {
----------------
Likewise, i would expect this can be outside of namespaces


================
Comment at: clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.cpp:295
+  case MtUnsafeCheck::LibcType::Any:
+    return hasAnyName(anyFunctions);
+  }
----------------
return anyOf(hasAnyName(posixFunctions), hasAnyName(glibcFunctions));


================
Comment at: clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.cpp:309-310
+void MtUnsafeCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(callExpr(callee(functionDecl(hasAnyMtUnsafeNames(Libc))))
+                         .bind("mt-unsafe"),
+                     this);
----------------
Is there any way to invert the direction of this matcher,
instead of checking each call that it's callee isn't one of the bad ones,
look through all function decls, and for all the bad ones, diagnose all calls to them?


================
Comment at: clang-tools-extra/docs/ReleaseNotes.rst:111
+
+  Finds thread-unsafe functions usage.
+
----------------
<...>, Currently knows about POSIX and GLIBC.

or something along those lines


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90944/new/

https://reviews.llvm.org/D90944



More information about the cfe-commits mailing list