Issue 235705
Summary [clang-analyzer] WebKit destructor checker prints unrelated deep base types before checking their namespace
Labels new issue
Assignees
Reporter adamtheturtle
    Tested with official LLVM 23.1.4 (`7a941dfb2877a0b8cf30323fefa85ad019e0b0f5`) on Ubuntu 24.04.5, Linux AArch64.

The source has no WTF classes and no reference-counting interface.
This checker should reject the namespace exemption cheaply.
Ordinary syntax checking of this source completes promptly.

```cpp
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>>>>>>>>>>>>>>>>>>>>>>>>>>>> {};
```

Run from the [reproducer bundle](https://github.com/adamtheturtle/literalizer/blob/609a43270048ac5e733e14b320fc667f6cc5429e/ci/llvm-upstream/README.md):

```sh
timeout 10s clang-tidy reproducers/webkit.cpp --checks=-*,clang-analyzer-webkit.RefCntblBaseVirtualDtor --config={} -- -std=c++20
```

The unmodified release exceeded the ten-second limit (exit 124).
The same input completed in 0.022 seconds with the [candidate implementation](https://github.com/adamtheturtle/literalizer/blob/609a43270048ac5e733e14b320fc667f6cc5429e/ci/llvm-upstream/patches/webkit.patch).
These are single sequential wall-clock samples, not statistical benchmarks.
Raw commands and outputs are in [measurements.json](https://github.com/adamtheturtle/literalizer/blob/609a43270048ac5e733e14b320fc667f6cc5429e/ci/llvm-upstream/measurements.json).

The exemption condition calls `T.getAsString()` before checking whether the declaring namespace is WTF.
Printing this instantiated base expands repeated allocator/type arguments.

Candidate fix: Check the namespace before calling `getAsString()`.
This reorders the same conjunction; it does not change which classes are exempt.
The candidate includes a compiler-analyzer regression test with no standard-library dependency.

The isolated patch applies to LLVM main `fac4500420cdeed42f35537a26eea1e4e17badf0` and contains a regression test.
The new test and the downstream semantic controls were run with the patched 23.1.4 tools; a complete build of current LLVM main has not been performed.

Prepared with AI assistance.

<details>
<summary>Candidate patch, including regression test</summary>

```diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
index b883cb78..1859536c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
@@ -199,8 +199,8 @@ public:
           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 0000000000000..aed8871ab793eb0afcb0acadeaffbcfc1575fe14
--- /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>


_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to