================
@@ -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()) {
+        const ParmVarDecl *ParmToAnnotate = PVD;
+        if (const FunctionDecl *CrossTUDecl = getCrossTUDecl(FD, SM))
+          if (unsigned Index = PVD->getFunctionScopeIndex();
----------------
usx95 wrote:

Why is this `if` needed ? Can this be > num params ?

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