Skip to content

Commit 938be89

Browse files
committed
Merging r344444 and r344445:
------------------------------------------------------------------------ r344444 | baloghadamsoftware | 2018-10-13 03:34:52 -0700 (Sat, 13 Oct 2018) | 11 lines [clang-tidy] Optimize query in bugprone-exception-escape Checking whether a functions throws indirectly may be very expensive because it needs to visit its whole call graph. Therefore we should first check whether the function is forbidden to throw and only check whether it throws afterward. This also seems to solve bug https://bugs.llvm.org/show_bug.cgi?id=39167 where the execution time is so long that it seems to hang. Differential Revision: https://reviews.llvm.org/D53187 ------------------------------------------------------------------------ ------------------------------------------------------------------------ r344445 | baloghadamsoftware | 2018-10-13 04:17:59 -0700 (Sat, 13 Oct 2018) | 3 lines [clang-tidy] Fix for typos in the tests for `bugprone-exception-escape` ------------------------------------------------------------------------ llvm-svn: 347921
1 parent 3ccd033 commit 938be89

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ void ExceptionEscapeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
187187

188188
void ExceptionEscapeCheck::registerMatchers(MatchFinder *Finder) {
189189
Finder->addMatcher(
190-
functionDecl(allOf(throws(unless(isIgnored(IgnoredExceptions))),
191-
anyOf(isNoThrow(), cxxDestructorDecl(),
190+
functionDecl(allOf(anyOf(isNoThrow(), cxxDestructorDecl(),
192191
cxxConstructorDecl(isMoveConstructor()),
193192
cxxMethodDecl(isMoveAssignmentOperator()),
194193
hasName("main"), hasName("swap"),
195-
isEnabled(FunctionsThatShouldNotThrow))))
194+
isEnabled(FunctionsThatShouldNotThrow)),
195+
throws(unless(isIgnored(IgnoredExceptions)))))
196196
.bind("thrower"),
197197
this);
198198
}

clang-tools-extra/docs/clang-tidy/checks/bugprone-exception-escape.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ are always possible to implement in a non throwing way. Non throwing ``swap()``
2121
operations are also used to create move operations. A throwing ``main()``
2222
function also results in unexpected termination.
2323

24+
WARNING! This check may be expensive on large source files.
25+
2426
Options
2527
-------
2628

clang-tools-extra/test/clang-tidy/bugprone-exception-escape.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,31 @@ void this_counts(int n) noexcept {
258258
throw ignored1();
259259
}
260260

261+
void thrower(int n) {
262+
throw n;
263+
}
264+
265+
int directly_recursive(int n) noexcept {
266+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in function 'directly_recursive' which should not throw exceptions
267+
if (n == 0)
268+
thrower(n);
269+
return directly_recursive(n);
270+
}
271+
272+
int indirectly_recursive(int n) noexcept;
273+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in function 'indirectly_recursive' which should not throw exceptions
274+
275+
int recursion_helper(int n) {
276+
indirectly_recursive(n);
277+
}
278+
279+
int indirectly_recursive(int n) noexcept {
280+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in function 'indirectly_recursive' which should not throw exceptions
281+
if (n == 0)
282+
thrower(n);
283+
return recursion_helper(n);
284+
}
285+
261286
int main() {
262287
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in function 'main' which should not throw exceptions
263288
throw 1;

0 commit comments

Comments
 (0)