[clang] [alpha.webkit.UncountedLocalVarsChecker] Ignore local vars of JSC::VM& type (PR #91068)

Mikhail R. Gadelha via cfe-commits cfe-commits at lists.llvm.org
Sat May 4 09:16:17 PDT 2024


https://github.com/mikhailramalho updated https://github.com/llvm/llvm-project/pull/91068

>From dde31272c1599a699c49117c1612ae72d0491384 Mon Sep 17 00:00:00 2001
From: "Mikhail R. Gadelha" <mikhail at igalia.com>
Date: Sat, 4 May 2024 13:08:32 -0300
Subject: [PATCH] [alpha.webkit.UncountedLocalVarsChecker] Ignore local vars of
 JSC::VM& type

This patch also updates safeGetName to get names from operators without
hitting an assertion
---
 .../StaticAnalyzer/Checkers/WebKit/ASTUtils.h | 11 +++++----
 .../WebKit/UncountedLocalVarsChecker.cpp      | 23 +++++++++++++++++++
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h
index e35ea4ef05dd17..d9049fea897be1 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h
@@ -67,12 +67,13 @@ template <typename T> std::string safeGetName(const T *ASTNode) {
   if (!ND)
     return "";
 
-  // In case F is for example "operator|" the getName() method below would
-  // assert.
-  if (!ND->getDeclName().isIdentifier())
-    return "";
+  if (const auto *Identifier = ND->getIdentifier())
+    return Identifier->getName().str();
 
-  return ND->getName().str();
+  std::string Name;
+  llvm::raw_string_ostream OS(Name);
+  ND->printName(OS);
+  return OS.str().empty() ? "" : OS.str();
 }
 
 } // namespace clang
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
index 6036ad58cf253c..2d33e63f66ad7c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
@@ -225,11 +225,34 @@ class UncountedLocalVarsChecker
     }
   }
 
+  bool isVarIsAVMRefType(const VarDecl *V) const {
+    auto* type = V->getType()->getAs<LValueReferenceType>();
+    if(!type)
+      return false;
+
+    auto ClassDecl = type->getPointeeType()->getUnqualifiedDesugaredType()->getAsCXXRecordDecl();
+    if (!ClassDecl)
+      return false;
+
+    auto *NsDecl = ClassDecl->getParent();
+    if (!NsDecl || !isa<NamespaceDecl>(NsDecl))
+      return false;
+
+    auto ClsNameStr = safeGetName(ClassDecl);
+    auto NamespaceName = safeGetName(NsDecl);
+
+    // FIXME: These should be implemented via attributes.
+    return NamespaceName == "JSC" && ClsNameStr == "VM";
+  }
+
   bool shouldSkipVarDecl(const VarDecl *V) const {
     assert(V);
     if (!V->isLocalVarDecl())
       return true;
 
+    if (isVarIsAVMRefType(V))
+      return true;
+
     return false;
   }
 



More information about the cfe-commits mailing list