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

Ryosuke Niwa via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 20 17:24:31 PST 2024


https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/117090

Only call getThisType() on an instance method.

>From 31481cda425206408eb3aeef844503b110dfaa4d Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at webkit.org>
Date: Wed, 20 Nov 2024 17:23:18 -0800
Subject: [PATCH] [webkit.UncountedLambdaCapturesChecker] Fix debug assertion
 failure.

Only call getThisType() on an instance method.
---
 .../Checkers/WebKit/UncountedLambdaCapturesChecker.cpp        | 3 ++-
 .../Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp    | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)

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