================
@@ -2969,6 +3009,46 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings(
CallableVisitor(CallAnalyzers, TU->getOwningModule())
.TraverseTranslationUnitDecl(TU);
}
+
+ if (S.getLangOpts().EnableLifetimeSafety && S.getLangOpts().CPlusPlus &&
+ S.getLangOpts().EnableLifetimeSafetyInferencePostOrder) {
+ llvm::SmallVector<const FunctionDecl *, 64> AllFunctions;
+ auto AddFunctionToList = [&](const Decl *D) -> void {
+ if (const auto *FD = dyn_cast<FunctionDecl>(D))
+ if (FD->doesThisDeclarationHaveABody() &&
+ !S.getSourceManager().isInSystemHeader(FD->getLocation()))
+ AllFunctions.push_back(FD);
+ };
+ CallableVisitor(AddFunctionToList, TU->getOwningModule())
+ .TraverseTranslationUnitDecl(TU);
+
+ if (AllFunctions.empty())
+ return;
+
+ clang::CallGraph CG;
+ for (const clang::FunctionDecl *FD : AllFunctions)
+ CG.getOrInsertNode(const_cast<clang::FunctionDecl *>(FD));
+
+ CallGraphBuilder Builder(CG, S);
+ for (const clang::FunctionDecl *FD : AllFunctions)
+ Builder.addCallsFrom(const_cast<clang::FunctionDecl *>(FD));
+
+ lifetimes::LifetimeSafetyReporterImpl Reporter(S);
+ for (auto *Node : llvm::post_order(&CG)) {
+ if (const clang::FunctionDecl *CanonicalFD =
----------------
usx95 wrote:
nit: reduce indentation by using `continue`.
```cpp
const clang::FunctionDecl *FD =
dyn_cast_or_null<clang::FunctionDecl>(Node->getDecl());
if (!FD)
continue;
FD = FD->getDefinition();
if (!FD)
continue;
```
https://github.com/llvm/llvm-project/pull/174178
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits