================
@@ -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))
----------------
usx95 wrote:
I would also be in favour of keeping the `LifetimeSafetyReporter` very lean. It
is an unfortunate abstraction for not exposing `Sema` to the `Analysis` lib.
https://github.com/llvm/llvm-project/pull/171972
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits