Skip to content

Commit

Permalink
Add support for polymorphic types that use destroying delete instead …
Browse files Browse the repository at this point in the history
…of a

virtual destructor.
The change makes types with an `operator delete(..., std::destroying_delete_t)` to be handled the same way abstract classes are handled (ie with unique_ptr), allowing subclasses to be constructed during marshalling.

Tested:
  Presubmit
  TGP with custom binary (rerun) OCL:633257130:BASE:634387810:1715870484576:3c4e7d32
PiperOrigin-RevId: 634394623
  • Loading branch information
CLIF Team authored and rwgk committed Aug 27, 2024
1 parent 928a7fb commit 25ea379
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clif/backend/matcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,9 @@ void ClifMatcher::SetTypePropertiesHelper(clang::CXXRecordDecl* clang_decl,
!ast_->DestructorIsAccessible(clang_decl)) {
clif_decl->set_cpp_movable(false);
}
if (clang_decl->isAbstract()) {
if (clang_decl->isAbstract() ||
std::any_of(clang_decl->method_begin(), clang_decl->method_end(),
[](auto* md) { return md->isDestroyingOperatorDelete(); })) {
clif_decl->set_cpp_abstract(true);
}
SetUniqueClassProperties(clang_decl, clif_decl);
Expand Down
11 changes: 11 additions & 0 deletions clif/backend/matcher_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,11 @@ TEST_F(ClifMatcherTest, TestMatchSetTypeProperties) {
"name { cpp_name: 'AbstractClass' } "
"}", &decl);
EXPECT_TRUE(decl.class_().cpp_abstract());
TestMatch(
"decltype: CLASS class_ { "
"name { cpp_name: 'DestroyingDeleteClass' } "
"}", &decl);
EXPECT_TRUE(decl.class_().cpp_abstract());
TestMatch(
"decltype: CLASS class_ { "
"name { cpp_name: 'PrivateDestructorClass' } "
Expand Down Expand Up @@ -972,6 +977,12 @@ TEST_F(ClifMatcherTest, TestCppAbstract) {
"params { type { lang_type: 'AbstractClass' "
" cpp_type: 'AbstractClass' } } }", &decl);
EXPECT_TRUE(decl.func().params(0).type().cpp_abstract());

TestMatch("decltype: FUNC func { "
"name { cpp_name: 'FuncAbstractParam' } "
"params { type { lang_type: 'DestroyingDeleteClass' "
" cpp_type: 'DestroyingDeleteClass' } } }", &decl);
EXPECT_TRUE(decl.func().params(0).type().cpp_abstract());
}

TEST_F(ClifMatcherTest, TestMatchAndSetTemplateTypes) {
Expand Down
13 changes: 13 additions & 0 deletions clif/backend/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
#define CLIF_BACKEND_TEST_H_

#include <stdint.h>

namespace std {
struct destroying_delete_t {
explicit destroying_delete_t() = default;
};
inline constexpr destroying_delete_t destroying_delete{};
} // namespace std

// These are all declared in the same file to make lookup inside the
// TU complicated enough to be convincing.

Expand Down Expand Up @@ -105,6 +113,10 @@ class AbstractClass {
virtual void Func() = 0;
};

class DestroyingDeleteClass {
public:
void operator delete(DestroyingDeleteClass*, std::destroying_delete_t);
};

class DerivedClass : public Class {
public:
Expand Down Expand Up @@ -317,6 +329,7 @@ class ClassOverridesPureVirtual: public ClassPureVirtual {
void SomeFunctionNotPureVirtual();
void FuncAbstractParam(const ClassPureVirtual* x);
void FuncAbstractParam(const AbstractClass& x);
void FuncAbstractParam(const DestroyingDeleteClass& x);
void FuncForwardDeclared(const Globally::Qualified::ForwardDecl* x);

// tests to be sure we don't match a return in const param.
Expand Down

0 comments on commit 25ea379

Please sign in to comment.