================
@@ -160,11 +161,35 @@ 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 ParmVarDecl &PVD,
+                                            SourceManager &SM) {
+    const auto *FD = dyn_cast<FunctionDecl>(PVD.getDeclContext());
+    if (!FD)
+      return nullptr;
+    if (!FD->isExternallyVisible())
+      return nullptr;
+    const FunctionDecl *CanonicalDecl = FD->getCanonicalDecl();
+    if (CanonicalDecl != FD && SM.getFileID(FD->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) {
+      if (const FunctionDecl *CrossTUDecl = getCrossTUDecl(*PVD, SM))
----------------
kashika0112 wrote:

The reason I added the logic here was to keep suggestAnnotations in 
LifetimeSafetyReporter simple and just about issuing diagnostics at the given 
locations. I can add it to the reporter and move the helper function 
`getCrossTUDecl` there if it seems more aligned with the design. Let me know.

https://github.com/llvm/llvm-project/pull/171972
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to