https://github.com/mikhailramalho updated https://github.com/llvm/llvm-project/pull/91068
>From a770060da101720ffddc033fd37db790eaa17710 Mon Sep 17 00:00:00 2001 From: "Mikhail R. Gadelha" <mikh...@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 | 25 +++++++++++++++++++ 2 files changed, 31 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..2f5e8e139709f6 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp @@ -225,11 +225,36 @@ 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; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits