================
@@ -164,50 +171,70 @@ 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,
+  static const FunctionDecl *getCrossTUDecl(const FunctionDecl &FD,
                                             SourceManager &SM) {
-    const auto *FD = dyn_cast<FunctionDecl>(PVD.getDeclContext());
-    if (!FD)
-      return nullptr;
-    if (!FD->isExternallyVisible())
+    if (!FD.isExternallyVisible())
       return nullptr;
-    const FileID DefinitionFile = SM.getFileID(FD->getLocation());
-    for (const FunctionDecl *Redecl : FD->redecls())
+    const FileID DefinitionFile = SM.getFileID(FD.getLocation());
+    for (const FunctionDecl *Redecl : FD.redecls())
       if (SM.getFileID(Redecl->getLocation()) != DefinitionFile)
         return Redecl;
 
     return nullptr;
   }
 
+  static const FunctionDecl *getCrossTUDecl(const ParmVarDecl &PVD,
+                                            SourceManager &SM) {
+    if (const auto *FD = dyn_cast<FunctionDecl>(PVD.getDeclContext()))
+      return getCrossTUDecl(*FD, SM);
+    return nullptr;
+  }
+
   void suggestAnnotations() {
     if (!Reporter)
       return;
     SourceManager &SM = AST.getSourceManager();
-    for (const auto &[PVD, EscapeExpr] : AnnotationWarningsMap) {
-      if (const FunctionDecl *CrossTUDecl = getCrossTUDecl(*PVD, SM))
-        Reporter->suggestAnnotation(
-            SuggestionScope::CrossTU,
-            CrossTUDecl->getParamDecl(PVD->getFunctionScopeIndex()),
-            EscapeExpr);
-      else
-        Reporter->suggestAnnotation(SuggestionScope::IntraTU, PVD, EscapeExpr);
+    for (const auto &[Target, EscapeExpr] : AnnotationWarningsMap) {
----------------
Xazax-hun wrote:

Nit, since both `Target` and `EscapeExpr` are relatively small trivial types I 
wonder if it would be better to iterate over them by value. 

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

Reply via email to