================
@@ -164,50 +171,68 @@ 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 (auto [Target, EscapeExpr] : AnnotationWarningsMap) {
+ if (const auto *PVD = Target.dyn_cast<const ParmVarDecl *>()) {
+ if (const FunctionDecl *CrossTUDecl = getCrossTUDecl(*PVD, SM))
+ Reporter->suggestAnnotation(
+ SuggestionScope::CrossTU,
+ CrossTUDecl->getParamDecl(PVD->getFunctionScopeIndex()),
+ EscapeExpr);
+ else
+ Reporter->suggestAnnotation(SuggestionScope::IntraTU, PVD,
+ EscapeExpr);
+ } else if (const auto *MD = Target.dyn_cast<const CXXMethodDecl *>()) {
+ if (const FunctionDecl *CrossTUDecl = getCrossTUDecl(*MD, SM))
+ Reporter->suggestAnnotation(SuggestionScope::CrossTU,
+ cast<CXXMethodDecl>(CrossTUDecl),
+ EscapeExpr);
+ else
+ Reporter->suggestAnnotation(SuggestionScope::IntraTU, MD,
EscapeExpr);
+ }
}
}
----------------
kashika0112 wrote:
Done
https://github.com/llvm/llvm-project/pull/176703
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits