[clang] 9492744 - [webkit.UncountedLambdaCapturesChecker] Fix debug assertion failure. (#117090)

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 21 13:29:19 PST 2024


Author: Ryosuke Niwa
Date: 2024-11-21T13:29:15-08:00
New Revision: 9492744dc3bb483f6a723a6abef0195b93e25cde

URL: https://github.com/llvm/llvm-project/commit/9492744dc3bb483f6a723a6abef0195b93e25cde
DIFF: https://github.com/llvm/llvm-project/commit/9492744dc3bb483f6a723a6abef0195b93e25cde.diff

LOG: [webkit.UncountedLambdaCapturesChecker] Fix debug assertion failure. (#117090)

Only call getThisType() on an instance method.

Added: 
    

Modified: 
    clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
    clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
index 3fb763e72e6809..9312bf0af16dbf 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
@@ -51,7 +51,8 @@ class UncountedLambdaCapturesChecker
 
       bool TraverseCXXMethodDecl(CXXMethodDecl *CXXMD) override {
         llvm::SaveAndRestore SavedDecl(ClsType);
-        ClsType = CXXMD->getThisType();
+        if (CXXMD && CXXMD->isInstance())
+          ClsType = CXXMD->getThisType();
         return DynamicRecursiveASTVisitor::TraverseCXXMethodDecl(CXXMD);
       }
 

diff  --git a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
index 9bfcdea04755d2..b63ffed8809fef 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
@@ -1,5 +1,9 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify %s
 
+struct A {
+  static void b();
+};
+
 struct RefCountable {
   void ref() {}
   void deref() {}


        


More information about the cfe-commits mailing list