Skip to content

[analyzer] Backport deducing "this" crash fix #84194

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

Merged

Conversation

steakhal
Copy link
Contributor

@steakhal steakhal commented Mar 6, 2024

[analyzer] Fix crash on dereference invalid return value of getAdjustedParameterIndex() (#83585)

Fixes #78810
Thanks for @Snape3058 's comment


Co-authored-by: miaozhiyuan [email protected]
(cherry picked from commit d4687fe)

@steakhal steakhal added this to the LLVM 18.X Release milestone Mar 6, 2024
@steakhal steakhal requested review from Xazax-hun and cor3ntin March 6, 2024 16:42
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Mar 6, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 6, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Balazs Benics (steakhal)

Changes

[analyzer] Fix crash on dereference invalid return value of getAdjustedParameterIndex() (#83585)

Fixes #78810
Thanks for Snape3058 's comment


Co-authored-by: miaozhiyuan <[email protected]>
(cherry picked from commit d4687fe)


Full diff: https://github.com/llvm/llvm-project/pull/84194.diff

2 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Core/CallEvent.cpp (+1-1)
  • (modified) clang/test/Analysis/cxx2b-deducing-this.cpp (+11)
diff --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
index 0ac1d91b79beb5..bc14aea27f6736 100644
--- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -1409,7 +1409,7 @@ CallEventManager::getSimpleCall(const CallExpr *CE, ProgramStateRef State,
   if (const auto *OpCE = dyn_cast<CXXOperatorCallExpr>(CE)) {
     const FunctionDecl *DirectCallee = OpCE->getDirectCallee();
     if (const auto *MD = dyn_cast<CXXMethodDecl>(DirectCallee))
-      if (MD->isInstance())
+      if (MD->isImplicitObjectMemberFunction())
         return create<CXXMemberOperatorCall>(OpCE, State, LCtx, ElemRef);
 
   } else if (CE->getCallee()->getType()->isBlockPointerType()) {
diff --git a/clang/test/Analysis/cxx2b-deducing-this.cpp b/clang/test/Analysis/cxx2b-deducing-this.cpp
index d22a897097bec0..2ec9e96bf0f84f 100644
--- a/clang/test/Analysis/cxx2b-deducing-this.cpp
+++ b/clang/test/Analysis/cxx2b-deducing-this.cpp
@@ -60,3 +60,14 @@ void top() {
   s.c();
   s.c(11);
 }
+
+
+struct S2 {
+  bool operator==(this auto, S2) {
+    return true;
+  }
+};
+void use_deducing_this() {
+  int result = S2{} == S2{}; // no-crash
+  clang_analyzer_dump(result); // expected-warning {{1 S32b}}
+}

@steakhal
Copy link
Contributor Author

steakhal commented Mar 6, 2024

I didn't mention this fix in the release notes, as deducing "this" is a new feature.

Copy link
Collaborator

@Xazax-hun Xazax-hun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

…edParameterIndex() (#83585)

Fixes #78810
Thanks for Snape3058 's comment

---------

Co-authored-by: miaozhiyuan <[email protected]>
(cherry picked from commit d4687fe)
@tstellar tstellar force-pushed the backport-deducing-this-crash-fix branch from 985d14a to 1de8ea7 Compare March 13, 2024 04:53
@tstellar tstellar merged commit 1de8ea7 into llvm:release/18.x Mar 13, 2024
@steakhal steakhal deleted the backport-deducing-this-crash-fix branch March 13, 2024 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:static analyzer clang Clang issues not falling into any other category release:backport
Projects
Development

Successfully merging this pull request may close these issues.

5 participants