================
@@ -163,8 +164,25 @@ class LifetimeChecker {
   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;
+      // For public functions (external linkage), find the header declaration
+      // to annotate; otherwise, treat as private and annotate the definition.
+      if (FD->isExternallyVisible()) {
+        const FunctionDecl *CanonicalFD = FD->getCanonicalDecl();
+        const ParmVarDecl *ParmToAnnotate = PVD;
+        if (CanonicalFD != FD && SM.getFileID(FD->getLocation()) !=
+                                     SM.getFileID(CanonicalFD->getLocation()))
+          if (unsigned Index = PVD->getFunctionScopeIndex();
+              Index < CanonicalFD->getNumParams())
+            ParmToAnnotate = CanonicalFD->getParamDecl(Index);
+        Reporter->suggestAnnotationsPublic(ParmToAnnotate, EscapeExpr);
+      } else
+        Reporter->suggestAnnotationsPrivate(PVD, EscapeExpr);
----------------
kashika0112 wrote:

Done

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