Skip to content

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 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