Skip to content

Commit

Permalink
[clang-tidy] Do not emit bugprone-exception-escape warnings from coro…
Browse files Browse the repository at this point in the history
…utines

All exceptions thrown in coroutine bodies are caught and
unhandled_exception member of the coroutine promise type is called.
In accordance with the existing rules of diagnostics related to
exceptions thrown in functions marked noexcept, even if the promise
type's constructor, get_return_object, or unhandled_exception
throws, diagnostics should not be emitted.

Fixes #61905.

Reviewed By: PiotrZSL, ChuanqiXu

Differential Revision: https://reviews.llvm.org/D147417
  • Loading branch information
denizevrenci authored and PiotrZSL committed May 30, 2023
1 parent 6cdc07a commit 6219b7c
Show file tree
Hide file tree
Showing 4 changed files with 739 additions and 0 deletions.
13 changes: 13 additions & 0 deletions clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
Expand Up @@ -523,6 +523,19 @@ ExceptionAnalyzer::ExceptionInfo ExceptionAnalyzer::throwsException(
ExceptionInfo Excs =
throwsException(DefaultInit->getExpr(), Caught, CallStack);
Results.merge(Excs);
} else if (const auto *Coro = dyn_cast<CoroutineBodyStmt>(St)) {
for (const Stmt *Child : Coro->childrenExclBody()) {
ExceptionInfo Excs = throwsException(Child, Caught, CallStack);
Results.merge(Excs);
}
ExceptionInfo Excs = throwsException(Coro->getBody(), Caught, CallStack);
for (const Type *Throwable : Excs.getExceptionTypes()) {
if (const auto ThrowableRec = Throwable->getAsCXXRecordDecl()) {
ExceptionInfo DestructorExcs =
throwsException(ThrowableRec->getDestructor(), CallStack);
Results.merge(DestructorExcs);
}
}
} else {
for (const Stmt *Child : St->children()) {
ExceptionInfo Excs = throwsException(Child, Caught, CallStack);
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Expand Up @@ -395,6 +395,10 @@ Changes in existing checks
<clang-tidy/checks/performance/no-automatic-move>`: warn on ``const &&``
constructors.

- Fixed :doc:`bugprone-exception-escape<clang-tidy/checks/bugprone/exception-escape>`
for coroutines where previously a warning would be emitted with coroutines
throwing exceptions in their bodies.

Removed checks
^^^^^^^^^^^^^^

Expand Down

0 comments on commit 6219b7c

Please sign in to comment.