-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Add the ability to exempt callees from the misc-coroutine-hostile-raii clang-tidy check #167778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-coroutines @llvm/pr-subscribers-clang-tidy Author: None (higher-performance) ChangesWhen you have code like Full diff: https://github.com/llvm/llvm-project/pull/167778.diff 3 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index a2d3d3ff1512d..a7b74944690b4 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -73,7 +73,9 @@ CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
RAIITypesList(utils::options::parseStringList(
Options.get("RAIITypesList", "std::lock_guard;std::scoped_lock"))),
AllowedAwaitablesList(utils::options::parseStringList(
- Options.get("AllowedAwaitablesList", ""))) {}
+ Options.get("AllowedAwaitablesList", ""))),
+ AllowedCallees(
+ utils::options::parseStringList(Options.get("AllowedCallees", ""))) {}
void CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
// A suspension happens with co_await or co_yield.
@@ -81,7 +83,9 @@ void CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
hasAttr(attr::Kind::ScopedLockable)))))
.bind("scoped-lockable");
auto OtherRAII = varDecl(typeWithNameIn(RAIITypesList)).bind("raii");
- auto AllowedSuspend = awaitable(typeWithNameIn(AllowedAwaitablesList));
+ auto AllowedSuspend = awaitable(
+ anyOf(typeWithNameIn(AllowedAwaitablesList),
+ callExpr(callee(functionDecl(hasAnyName(AllowedCallees))))));
Finder->addMatcher(
expr(anyOf(coawaitExpr(unless(AllowedSuspend)), coyieldExpr()),
forEachPrevStmt(
@@ -111,5 +115,7 @@ void CoroutineHostileRAIICheck::storeOptions(
utils::options::serializeStringList(RAIITypesList));
Options.store(Opts, "SafeAwaitableList",
utils::options::serializeStringList(AllowedAwaitablesList));
+ Options.store(Opts, "SafeCallees",
+ utils::options::serializeStringList(AllowedCallees));
}
} // namespace clang::tidy::misc
diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.h b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.h
index 768b62ef07f90..12ad1b1e0e220 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.h
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.h
@@ -46,6 +46,9 @@ class CoroutineHostileRAIICheck : public ClangTidyCheck {
// List of fully qualified awaitable types which are considered safe to
// co_await.
std::vector<StringRef> AllowedAwaitablesList;
+ // List of callees whose return values are considered safe to directly
+ // co_await.
+ std::vector<StringRef> AllowedCallees;
};
} // namespace clang::tidy::misc
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
index c23c355dac1b2..ec6ddec56e1f2 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
@@ -1,7 +1,8 @@
// RUN: %check_clang_tidy -std=c++20 %s misc-coroutine-hostile-raii %t \
// RUN: -config="{CheckOptions: {\
// RUN: misc-coroutine-hostile-raii.RAIITypesList: 'my::Mutex; ::my::other::Mutex', \
-// RUN: misc-coroutine-hostile-raii.AllowedAwaitablesList: 'safe::awaitable; ::transformable::awaitable' \
+// RUN: misc-coroutine-hostile-raii.AllowedAwaitablesList: 'safe::awaitable; ::transformable::awaitable', \
+// RUN: misc-coroutine-hostile-raii.AllowedCallees: 'safe::AwaitFunc; ::safe::Obj::AwaitMethod' \
// RUN: }}"
namespace std {
@@ -145,12 +146,18 @@ namespace safe {
void await_suspend(std::coroutine_handle<>) noexcept {}
void await_resume() noexcept {}
};
+ std::suspend_always AwaitFunc();
+ struct Obj {
+ std::suspend_always AwaitMethod();
+ };
} // namespace safe
ReturnObject RAIISafeSuspendTest() {
absl::Mutex a;
co_await safe::awaitable{};
using other = safe::awaitable;
co_await other{};
+ co_await safe::AwaitFunc();
+ co_await safe::Obj().AwaitMethod();
}
// ================================================================================
|
EugeneZelenko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please mention changes in documentation and Release Notes.
55ff6cf to
dab872f
Compare
|
Done, thanks. |
…i clang-tidy check
dab872f to
8e6667b
Compare
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/30855 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/46/builds/26284 Here is the relevant piece of the build log for the reference |
…i clang-tidy check (llvm#167778)
When you have code like
co_await foo(),foomay know for a fact that it is returning an object that is safe to hold a mutex across. There is currently no way to exempt these. This PR adds support for such exemptions.