aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClement Courbet <courbet@google.com>2024-06-25 07:53:44 +0200
committerGitHub <noreply@github.com>2024-06-25 07:53:44 +0200
commit8348d720ef913b0ff92b468be2eb9f4ea273cb5a (patch)
treeb94e31023a5f473c2d9872f4a743691d5a90d7e0
parentc393121778d877661f6b50cc3b3c582ac1654437 (diff)
downloadllvm-8348d720ef913b0ff92b468be2eb9f4ea273cb5a.zip
llvm-8348d720ef913b0ff92b468be2eb9f4ea273cb5a.tar.gz
llvm-8348d720ef913b0ff92b468be2eb9f4ea273cb5a.tar.bz2
[clang-tidy] Fix assert in performance-unnecessary-copy-init. (#96506)
`GetDirectCallee` can be null. Fixes #96498.
-rw-r--r--clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp2
-rw-r--r--clang-tools-extra/docs/ReleaseNotes.rst2
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp9
3 files changed, 11 insertions, 2 deletions
diff --git a/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp b/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
index a6062cc..106feb7 100644
--- a/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
@@ -296,7 +296,7 @@ AST_MATCHER_P(DeclRefExpr, doesNotMutateObject, int, Indirections) {
return false;
}
const auto *const Method =
- dyn_cast<CXXMethodDecl>(OpCall->getDirectCallee());
+ dyn_cast_or_null<CXXMethodDecl>(OpCall->getDirectCallee());
if (Method == nullptr) {
// This is not a member operator. Typically, a friend operator. These
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 16fdc20..7fcf5cf 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -398,7 +398,7 @@ Changes in existing checks
analyzed, so the check now handles the common patterns
`const auto e = (*vector_ptr)[i]` and `const auto e = vector_ptr->at(i);`.
Calls to mutable function where there exists a `const` overload are also
- handled.
+ handled. Fix crash in the case of a non-member operator call.
- Improved :doc:`readability-avoid-return-with-void-value
<clang-tidy/checks/readability/avoid-return-with-void-value>` check by adding
diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
index f259552..d02bb98 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
@@ -906,3 +906,12 @@ void negativeNonConstMemberExpr() {
}
}
+
+bool operator==(ExpensiveToCopyType, ExpensiveToCopyType);
+
+template<typename T> bool OperatorWithNoDirectCallee(T t) {
+ ExpensiveToCopyType a1;
+ ExpensiveToCopyType a2 = a1;
+ return a1 == t;
+}
+