[clang] [alpha.webkit.NoDeleteChecker] Allow no-delete default constructors (PR #201544)
Balázs Benics via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 4 04:24:52 PDT 2026
================
@@ -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
----------------
steakhal wrote:
According to godbolt, on x86_64 (Itenium ABI), `create` uses RVO.
https://godbolt.org/z/88h1a7dfW
Notice that I added a `ref_dtor_marker()` call to the Ref dtor, to see if it shows up in the assembly - and it doesn't which means that no Ref dtor is getting called, thus we have RVO.
I'm convinced now that our previous patch didn't quite get this right, and believes that no RVO happens here.
https://github.com/llvm/llvm-project/pull/201544
More information about the cfe-commits
mailing list