================
@@ -316,103 +316,87 @@ class LifetimeChecker {
}
}
- std::pair<const FunctionDecl *, WarningScope>
- getCanonicalFunctionDeclForAttr(const FunctionDecl *FDef) {
+ // Returns declarations that should be annotated with lifetime attributes
+ // in order to annotate FDef: the canonical declaration and the earliest
+ // redeclarations in each other file. This defines the placement policy for
+ // lifetime annotations. Each target is paired with its corresponding warning
+ // scope.
+ llvm::SmallVector<std::pair<const FunctionDecl *, WarningScope>, 2>
+ getTargetDeclsForAttr(const FunctionDecl *FDef) {
if (!FDef)
- return {nullptr, WarningScope::IntraTU};
+ return {};
assert(FDef->isThisDeclarationADefinition() &&
"Expected FunctionDecl to be a definition");
const auto &SM = FDef->getASTContext().getSourceManager();
- const FileID DefFile =
- SM.getFileID(SM.getExpansionLoc(FDef->getLocation()));
- const FunctionDecl *CanonicalDecl = FDef->getCanonicalDecl();
- WarningScope Scope = WarningScope::IntraTU;
- Scope = SM.getFileID(SM.getExpansionLoc(CanonicalDecl->getLocation())) !=
- DefFile
- ? WarningScope::CrossTU
- : WarningScope::IntraTU;
+ auto GetLoc = [&SM](const FunctionDecl *FD) {
+ return SM.getExpansionLoc(FD->getLocation());
+ };
+ auto GetFile = [&SM, &GetLoc](const FunctionDecl *FD) {
+ return SM.getFileID(GetLoc(FD));
+ };
- return {CanonicalDecl, Scope};
- }
+ const FileID DefFile = GetFile(FDef);
+ llvm::SmallVector<std::pair<FileID, const FunctionDecl *>, 2>
----------------
Xazax-hun wrote:
You could store `WarningScope` here if you calculated it more eagerly, I think.
https://github.com/llvm/llvm-project/pull/198784
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits