[clang] [clang][analyzer] Avoid printing non-WTF base types for destructor exemptions (PR #235713)

via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 26 04:47:18 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-static-analyzer-1

@llvm/pr-subscribers-clang

Author: Adam Dangoor (adamtheturtle)

<details>
<summary>Changes</summary>

The destructor exemption pretty-prints an instantiated base type before checking whether its namespace is WTF. Deep repeated template arguments make that printing exponential even for unrelated classes. Check the namespace first, preserving the same exemption condition.

Add a reduced analyzer regression with no standard-library dependency.

Fixes #<!-- -->235705.

Validation on macOS arm64 with assertions enabled, built independently against LLVM main `0a6c7b28e6a5ad99b4d564908a6dd0912f944328`:

- `clang`, `clang-tidy`, `clang-format`, and `FileCheck` build passed.
- Formatting checked with the compiler build's clang-format.
- webkit: 82 upstream lit tests passed.

The original Linux AArch64 LLVM 23.1.4 measurements are in the linked issue. Those are single wall-clock samples, not statistical benchmarks.

Prepared with AI assistance (OpenAI Codex).


---
Full diff: https://github.com/llvm/llvm-project/pull/235713.diff


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp (+2-2) 
- (added) clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor-deep-types.cpp (+7) 


``````````diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
index b883cb78705b6b..1859536cae6d69 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
@@ -199,8 +199,8 @@ class RefCntblBaseVirtualDtorChecker
           if (!C)
             continue;
 
-          bool isExempt = T.getAsString() == "NoVirtualDestructorBase" &&
-                          safeGetName(C->getParent()) == "WTF";
+          bool isExempt = safeGetName(C->getParent()) == "WTF" &&
+                          T.getAsString() == "NoVirtualDestructorBase";
           if (isExempt || ExemptDecls.contains(C)) {
             ExemptDecls.insert(RD);
             continue;
diff --git a/clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor-deep-types.cpp b/clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor-deep-types.cpp
new file mode 100644
index 00000000000000..aed8871ab793eb
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor-deep-types.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.RefCntblBaseVirtualDtor -std=c++17 -verify %s
+// expected-no-diagnostics
+
+template<class T> struct Alloc {};
+template<class T, class A> struct Storage {};
+template<class T, class A=Alloc<T>> struct Node : Storage<T,A> {};
+struct Derived : Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<int>>>>>>>>>>>>>>>>>>>>>>>>>>>> {};

``````````

</details>


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


More information about the cfe-commits mailing list