[PATCH] D146342: [-Wunsafe-buffer-usage] Move the whole analysis to the end of a translation unit

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 19 17:15:39 PDT 2023


NoQ added inline comments.


================
Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1478
+
+  struct CallableFinderCallback : MatchFinder::MatchCallback {
+    UnsafeBufferUsageHandler &Handler;
----------------
I think this entire matcher business can easily live in `AnalysisBasedWarnings::IssueWarnings(TU)`. Just because we're running at the end of TU, doesn't mean each warning will need to figure out how to traverse it. In our case the warning still acts on function-by-function basis, it just benefits from other functions being already parsed. I suspect that this is going to be the case for almost every other analysis-based warning we ever put there. So I think let's run the matcher once in `IssueWarnings(TU)` , for all warnings at once, and then invoke `void checkUnsafeBufferUsage(const Decl *D, ...)` directly from inside it, just like we did before the patch. If we ever run into a warning that really needs a `TranslationUnitDecl`, we can always invoke it from outside the matcher.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146342/new/

https://reviews.llvm.org/D146342



More information about the cfe-commits mailing list