[clang-tidy] implement concurrency-mt-unsafe
authorVasily Kulikov <segoon@yandex-team.ru>
Mon, 30 Nov 2020 09:20:08 +0000 (12:20 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Mon, 30 Nov 2020 09:27:17 +0000 (12:27 +0300)
commitcac5be495ed88b269ad7a3000305e714cce60e63
treee3eb13684b40db0beb2a70f5e194de81a4e8da33
parent8da7efbb0d5ec315a27b7b5286dbdd25694905ad
[clang-tidy] implement concurrency-mt-unsafe

Checks for some thread-unsafe functions against a black list
of known-to-be-unsafe functions. Usually they access static variables
without synchronization (e.g. gmtime(3)) or utilize signals
in a racy way (e.g. sleep(3)).

The patch adds a check instead of auto-fix as thread-safe alternatives
usually have API with an additional argument
(e.g. gmtime(3) v.s. gmtime_r(3)) or have a different semantics
(e.g. exit(3) v.s. __exit(3)), so it is a rather tricky
or non-expected fix.

An option specifies which functions in libc should be considered
thread-safe, possible values are `posix`, `glibc`,
or `any` (the most strict check). It defaults to 'any' as it is
unknown what target libc type is - clang-tidy may be run
on linux but check sources compiled for other *NIX.

The check is used in Yandex Taxi backend and has caught
many unpleasant bugs. A similar patch for coroutine-unsafe API
is coming next.

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D90944
clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp [new file with mode: 0644]
clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.h [new file with mode: 0644]
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/concurrency-mt-unsafe.rst [new file with mode: 0644]
clang-tools-extra/docs/clang-tidy/checks/list.rst
clang-tools-extra/test/clang-tidy/checkers/concurrency-mt-unsafe-any.cpp [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/checkers/concurrency-mt-unsafe-glibc.cpp [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/checkers/concurrency-mt-unsafe-posix.cpp [new file with mode: 0644]