[clang-tools-extra] 96c6d01 - [clang-tidy] Fix crash in modernize-use-noexcept on uninstantiated throw class
Zinovy Nis via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 15 22:14:12 PDT 2020
Author: Zinovy Nis
Date: 2020-09-16T08:13:00+03:00
New Revision: 96c6d012dfe2492891d0f0450dd7cd5f3c1ca88c
URL: https://github.com/llvm/llvm-project/commit/96c6d012dfe2492891d0f0450dd7cd5f3c1ca88c
DIFF: https://github.com/llvm/llvm-project/commit/96c6d012dfe2492891d0f0450dd7cd5f3c1ca88c.diff
LOG: [clang-tidy] Fix crash in modernize-use-noexcept on uninstantiated throw class
Bug: https://bugs.llvm.org/show_bug.cgi?id=47446
Differential Revision: https://reviews.llvm.org/D87627
Added:
Modified:
clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize-use-noexcept-opt.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
index cc4bc05a35dd..c4e7f12e74ac 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
@@ -77,13 +77,16 @@ void UseNoexceptCheck::check(const MatchFinder::MatchResult &Result) {
.getExceptionSpecRange();
}
+ assert(FnTy && "FunctionProtoType is null.");
+ if (isUnresolvedExceptionSpec(FnTy->getExceptionSpecType()))
+ return;
+
assert(Range.isValid() && "Exception Source Range is invalid.");
CharSourceRange CRange = Lexer::makeFileCharRange(
CharSourceRange::getTokenRange(Range), *Result.SourceManager,
Result.Context->getLangOpts());
- assert(FnTy && "FunctionProtoType is null.");
bool IsNoThrow = FnTy->isNothrow();
StringRef ReplacementStr =
IsNoThrow
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize-use-noexcept-opt.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize-use-noexcept-opt.cpp
index 92c1387d64d6..b0f52a18edf5 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize-use-noexcept-opt.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize-use-noexcept-opt.cpp
@@ -4,6 +4,7 @@
// This test is not run in C++17 or later because dynamic exception
// specifications were removed in C++17.
+using size_t = __SIZE_TYPE__;
class A {};
class B {};
@@ -19,6 +20,11 @@ void k() throw(int(int));
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: dynamic exception specification 'throw(int(int))' is deprecated; consider removing it instead [modernize-use-noexcept]
// CHECK-FIXES: void k() ;
+// Shouldn't crash due to llvm_unreachable in canThrow() on EST_Uninstantiated
+template <int> class c { void *operator new(size_t) throw (int);};
+void s() { c<1> doesnt_crash; }
+// CHECK-MESSAGES: :[[@LINE-2]]:53: warning: dynamic exception specification 'throw (int)' is deprecated; consider removing it instead [modernize-use-noexcept]
+
void foobar() throw(A, B)
{}
// CHECK-MESSAGES: :[[@LINE-2]]:15: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider removing it instead [modernize-use-noexcept]
More information about the cfe-commits
mailing list