[clang] [clang][StaticAnalyzer] Add enclosing Decl information to bug reports of RawPtrRef(LocalVars|Member)Checker (PR #214102)

Balázs Benics via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 6 13:52:29 PDT 2026


================
@@ -82,39 +82,15 @@ static std::string GetSignature(const FunctionDecl *Target) {
   return Signature;
 }
 
-static std::string GetEnclosingDeclContextSignature(const Decl *D) {
-  if (!D)
+static std::string GetEnclosingDeclContextSignature(const Decl *EnclosingDecl) {
+  if (!EnclosingDecl)
     return "";
 
-  if (const auto *ND = dyn_cast<NamedDecl>(D)) {
-    std::string DeclName;
-
-    switch (ND->getKind()) {
-    case Decl::Namespace:
-    case Decl::Record:
-    case Decl::CXXRecord:
-    case Decl::Enum:
-      DeclName = ND->getQualifiedNameAsString();
-      break;
-    case Decl::CXXConstructor:
-    case Decl::CXXDestructor:
-    case Decl::CXXConversion:
-    case Decl::CXXMethod:
-    case Decl::Function:
-      DeclName = GetSignature(dyn_cast_or_null<FunctionDecl>(ND));
-      break;
-    case Decl::ObjCMethod:
-      // ObjC Methods can not be overloaded, qualified name uniquely identifies
-      // the method.
-      DeclName = ND->getQualifiedNameAsString();
-      break;
-    default:
-      break;
-    }
-
-    return DeclName;
+  if (const auto *ND = dyn_cast<NamedDecl>(EnclosingDecl)) {
+    if (const auto *FD = dyn_cast<FunctionDecl>(EnclosingDecl))
+      return GetSignature(dyn_cast_or_null<FunctionDecl>(FD));
----------------
steakhal wrote:

You already have FD.
```suggestion
      return GetSignature(FD);
```

https://github.com/llvm/llvm-project/pull/214102


More information about the cfe-commits mailing list