[clang] [alpha.webkit.NoDeleteChecker] Allow no-delete default constructors (PR #201544)
Ryosuke Niwa via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 4 04:34:38 PDT 2026
https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/201544
>From b841eedfdb7b2ce61dc7337cb30001a4ce0adfb8 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at webkit.org>
Date: Thu, 4 Jun 2026 03:39:34 -0700
Subject: [PATCH] [alpha.webkit.NoDeleteChecker] Allow no-delete default
constructors
This PR fixes the bug in TrivialFunctionAnalysis that it treats a default trivial constructor
without an explicit body / definition as not "trivial". Fixed the bug by allowing the function
body to be missing when what we have is a trivial default constructor.
---
.../Checkers/WebKit/PtrTypesSemantics.cpp | 3 ++
.../Checkers/WebKit/nodelete-annotation.cpp | 42 +++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index d5ed7fc78148a..90151584a58c6 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -667,6 +667,9 @@ class TrivialFunctionAnalysisVisitor
if (!Visit(CtorInit->getInit()))
return false;
}
+ if (CtorDecl->isTrivial() && CtorDecl->isDefaultConstructor() &&
+ !CtorDecl->hasBody())
+ return true;
}
const Stmt *Body = D->getBody();
if (!Body)
diff --git a/clang/test/Analysis/Checkers/WebKit/nodelete-annotation.cpp b/clang/test/Analysis/Checkers/WebKit/nodelete-annotation.cpp
index a9c50cfb1f45f..0d78fa91046ed 100644
--- a/clang/test/Analysis/Checkers/WebKit/nodelete-annotation.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/nodelete-annotation.cpp
@@ -701,3 +701,45 @@ Ref<RefCountable> [[clang::annotate_type("webkit.nodelete")]] returnTypedefPrval
} // namespace returned_prvalue_typedef
+namespace create_with_default_constructor {
+
+ struct ObjectWithDefaultConstructorWithoutMemberVariables {
+ void ref() const;
+ void deref() const;
+
+ static auto [[clang::annotate_type("webkit.nodelete")]] create() {
+ return adoptRef(*new ObjectWithDefaultConstructorWithoutMemberVariables());
+ }
+ };
+
+ struct ObjectWithDefaultConstructorWithPODMemberVariables {
+ void ref() const;
+ void deref() const;
+
+ static auto [[clang::annotate_type("webkit.nodelete")]] create() {
+ return adoptRef(*new ObjectWithDefaultConstructorWithPODMemberVariables());
+ }
+
+ private:
+ int value { 0 };
+ RefCountable* ptr { nullptr };
+ };
+
+ struct ObjectWithOpaqueCtor {
+ ObjectWithOpaqueCtor();
+ };
+
+ struct ObjectWithDefaultConstructorWithOpaqueCtorMemberVariables {
+ void ref() const;
+ void deref() const;
+
+ static auto [[clang::annotate_type("webkit.nodelete")]] create() {
+ return adoptRef(*new ObjectWithDefaultConstructorWithOpaqueCtorMemberVariables());
+ // expected-warning at -1{{A function 'create' has [[clang::annotate_type("webkit.nodelete")]] but it contains code that could destruct an object}}
+ }
+
+ private:
+ ObjectWithOpaqueCtor obj;
+ };
+
+} // namespace create_with_default_constructor
More information about the cfe-commits
mailing list