================
@@ -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))
----------------
Xazax-hun wrote:
Since this logic is purely about error reporting, I wonder if this should
belong to the Reporter. I do not have strong feelings about this.
https://github.com/llvm/llvm-project/pull/171972
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits