[clang] [Lifetime Safety] Public Vs Private Annotation Suggestions (PR #171972)

Kashika Akhouri via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 15 00:34:57 PST 2025


================
@@ -160,11 +161,37 @@ class LifetimeChecker {
     }
   }
 
+  /// Returns the declaration of a function that is visible across translation
+  /// units, if such a declaration exists and is different from the definition.
+  static const FunctionDecl *getCrossTUDecl(const FunctionDecl *Definition,
+                                            SourceManager &SM) {
+    const FunctionDecl *CanonicalDecl = Definition->getCanonicalDecl();
+    if (CanonicalDecl != Definition &&
+        SM.getFileID(Definition->getLocation()) !=
+            SM.getFileID(CanonicalDecl->getLocation()))
+      return CanonicalDecl;
+    return nullptr;
+  }
+
   void suggestAnnotations() {
     if (!Reporter)
       return;
-    for (const auto &[PVD, EscapeExpr] : AnnotationWarningsMap)
-      Reporter->suggestAnnotation(PVD, EscapeExpr);
+    SourceManager &SM = AST.getSourceManager();
+    for (const auto &[PVD, EscapeExpr] : AnnotationWarningsMap) {
+      const auto *FD = dyn_cast<FunctionDecl>(PVD->getDeclContext());
+      if (!FD)
+        continue;
+      if (FD->isExternallyVisible()) {
----------------
kashika0112 wrote:

Okay done

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


More information about the cfe-commits mailing list