https://github.com/rniwa created
https://github.com/llvm/llvm-project/pull/177839
This PR adds the support for specifying
[[clang::annotate_type("webkit.nodelete")]] on a function return type, in which
case, the whole function is considered "trivial" or more precisely that it does
not trigger any destruction of an object.
>From b156a8a9e683eda84a64658d0a0af24895613071 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <[email protected]>
Date: Sat, 24 Jan 2026 22:28:12 -0800
Subject: [PATCH] Add nodelete annotation for WebKit checkers
This PR adds the support for specifying
[[clang::annotate_type("webkit.nodelete")]]
on a function return type, in which case, the whole function is considered
"trivial"
or more precisely that it does not trigger any destruction of an object.
---
.../Checkers/WebKit/PtrTypesSemantics.cpp | 11 +++++++++++
.../Analysis/Checkers/WebKit/uncounted-obj-arg.cpp | 6 ++++++
2 files changed, 17 insertions(+)
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index e056c35d6cf45..92fd612c11bc3 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -508,6 +508,17 @@ class TrivialFunctionAnalysisVisitor
if (auto *FnDecl = dyn_cast<FunctionDecl>(D)) {
if (FnDecl->isVirtualAsWritten())
return false;
+ auto ReturnType = FnDecl->getReturnType();
+ if (auto *Type = ReturnType.getTypePtrOrNull()) {
+ if (auto *AttrType = dyn_cast<AttributedType>(Type)) {
+ if (auto *Attr = AttrType->getAttr()) {
+ if (auto *AnnotateType = dyn_cast<AnnotateTypeAttr>(Attr)) {
+ if (AnnotateType->getAnnotation() == "webkit.nodelete")
+ return true;
+ }
+ }
+ }
+ }
}
return WithCachedResult(D, [&]() {
if (auto *CtorDecl = dyn_cast<CXXConstructorDecl>(D)) {
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index b83eaedf264e4..14a81aba1adc1 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -389,6 +389,9 @@ class RefCounted {
unsigned trivial71() { return std::bit_cast<unsigned>(nullptr); }
unsigned trivial72() { Number n { 5 }; return WTF::move(n).value(); }
+ unsigned [[clang::annotate_type("webkit.nodelete")]] nodelete1();
+ void [[clang::annotate_type("webkit.nodelete")]] nodelete2();
+
static RefCounted& singleton() {
static RefCounted s_RefCounted;
s_RefCounted.ref();
@@ -581,6 +584,9 @@ class UnrelatedClass {
getFieldTrivial().trivial70(); // no-warning
getFieldTrivial().trivial71(); // no-warning
+ getFieldTrivial().nodelete1(); // no-warning
+ getFieldTrivial().nodelete2(); // no-warning
+
RefCounted::singleton().trivial18(); // no-warning
RefCounted::singleton().someFunction(); // no-warning
RefCounted::otherSingleton().trivial18(); // no-warning
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits