HomePhabricator

[clang-tidy] implement concurrency-mt-unsafe

Authored by segoon on Nov 30 2020, 1:20 AM.

Description

[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

Details

Committed
lebedev.riNov 30 2020, 1:27 AM
Reviewer
lebedev.ri
Differential Revision
D90944: [clang-tidy] implement concurrency-mt-unsafe
Parents
rG8da7efbb0d5e: [clang-tidy] add concurrency module
Branches
Unknown
Tags
Unknown