-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-tidy] Fix assert in performance-unnecessary-copy-init. #96506
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
[clang-tidy] Fix assert in performance-unnecessary-copy-init. #96506
Conversation
@llvm/pr-subscribers-clang-tidy @llvm/pr-subscribers-clang-tools-extra Author: Clement Courbet (legrosbuffle) Changes
Fixes #96498. Full diff: https://github.com/llvm/llvm-project/pull/96506.diff 2 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp b/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
index a6062ccf42230..106feb7fb4172 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/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
index f259552dc8f1d..d02bb98cf583c 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;
+}
+
|
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.
lgtm, please update release note.
`GetDirectCallee` can be null. Fixes llvm#96498.
5034dc9
to
834b63a
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/161/builds/174 Here is the relevant piece of the build log for the reference:
|
…6506) `GetDirectCallee` can be null. Fixes llvm#96498.
GetDirectCallee
can be null.Fixes #96498.