[clang] [attributes][analyzer] Generalize [[clang::suppress]] to declarations. (PR #80371)

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 2 13:54:40 PST 2024


================
@@ -147,6 +147,20 @@ bool BugSuppression::isSuppressed(const PathDiagnosticLocation &Location,
     // done as well as perform a lot of work we'll never need.
     // Gladly, none of our on-by-default checkers currently need it.
     DeclWithIssue = ACtx.getTranslationUnitDecl();
+  } else {
+    // This is the fast path. However, we should still consider the topmost
+    // declaration that isn't TranslationUnitDecl, because we should respect
+    // attributes on the entire declaration chain.
+    while (true) {
----------------
haoNoQ wrote:

This is, uh, a somewhat premature performance optimization. I think I want to get rid of it, as discussed in #79398 (it's incorrect as well), but it probably requires a separate discussion.

The static analyzer normally always takes the fast path as every single "supported" checker fills in the data correctly.

This isn't just about scanning the TU *here* for discovering suppressed ranges, it's more about the fact that the static analyzer is so careful about not analyzing non-user code that normally it doesn't even deserialize PCHs if they aren't directly required for analysis. This is demonstrated by the lovely test case in [`clang/test/Analysis/check-deserialization.cpp`](https://github.com/llvm/llvm-project/blob/llvmorg-19-init/clang/test/Analysis/check-deserialization.cpp). A full TU scan here will cause these PCHs to be deserialized even though the rest of the analysis never needed to look at them.

I have some data that this can have significant performance impact. However, other tools such as clang-tidy never had such optimization (they always scan the entire TU indiscriminately) and this never stopped them from satisfying the usual performance expectations of static analysis tools. We've also abandoned this optimization in a downstream fork for a while and it seems perfectly livable.

So I want to either abandon this non-deserialization guarantee (simply always scan the entire TU), or find a different way to satisfy it (eg., collect those ranges eagerly during AST construction so that to avoid the after-the-fact scan; then if PCHs/modules are used, suppression ranges will make it into PCHs and get deserialized together with them as-needed). I'll probably try to do some of that in the coming weeks but I wanted this patch to be independent from that so that to get the attribute's behavior to reasonable shape without breaking anything else.

https://github.com/llvm/llvm-project/pull/80371


More information about the cfe-commits mailing list