Skip to content

IRGen: correct some type deletion #83321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/IRGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ add_swift_host_library(swiftIRGen STATIC
transformutils
irprinter
)
target_compile_options(swiftIRGen PRIVATE
$<$<AND:$<PLATFORM_ID:Linux>,$<CXX_COMPILER_ID:Clang>>:-fsized-deallocation>)
target_link_libraries(swiftIRGen INTERFACE
clangCodeGen
clangAST)
Expand Down
14 changes: 11 additions & 3 deletions lib/IRGen/GenExistential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ namespace {
class ExistentialTypeInfoBase : public Base,
private llvm::TrailingObjects<Derived, const ProtocolDecl *> {
friend class llvm::TrailingObjects<Derived, const ProtocolDecl *>;
using Tail = llvm::TrailingObjects<Derived, const ProtocolDecl *>;

/// The number of non-trivial protocols for this existential.
unsigned NumStoredProtocols;
Expand Down Expand Up @@ -157,12 +158,19 @@ namespace {
create(ArrayRef<const ProtocolDecl *> protocols, As &&...args)
{
void *buffer = operator new(
llvm::TrailingObjects<Derived, const ProtocolDecl *>::
template totalSizeToAlloc<const ProtocolDecl *>(
protocols.size()));
Tail::template totalSizeToAlloc<const ProtocolDecl *>(
protocols.size()));
return new (buffer) Derived(protocols, std::forward<As>(args)...);
}

void operator delete(void *ptr) {
const auto *pThis = static_cast<ExistentialTypeInfoBase *>(ptr);
const size_t count = pThis->NumStoredProtocols;
const size_t size =
Tail::template totalSizeToAlloc<const ProtocolDecl *>(count);
::operator delete(ptr, size);
}

/// Returns the number of protocol witness tables directly carried
/// by values of this type.
unsigned getNumStoredProtocols() const { return NumStoredProtocols; }
Expand Down
7 changes: 7 additions & 0 deletions lib/IRGen/GenRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ class RecordTypeInfoImpl : public Base,
return new(buffer) Impl(fields, std::forward<As>(args)...);
}

void operator delete(void *ptr) {
const auto *pThis = static_cast<RecordTypeInfoImpl *>(ptr);
const size_t count = pThis->NumFields;
const size_t size = Impl::template totalSizeToAlloc<FieldImpl>(count);
::operator delete(ptr, size);
}

bool areFieldsABIAccessible() const {
return AreFieldsABIAccessible;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/IRGen/ProtocolInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ class ProtocolInfo final :
ProtocolInfoKind kind);

public:
void operator delete(void *ptr) {
const auto *pThis = static_cast<ProtocolInfo *>(ptr);
const size_t count = pThis->NumTableEntries;
const size_t size = totalSizeToAlloc<WitnessTableEntry>(count);
::operator delete(ptr, size);
}

/// The number of witness slots in a conformance to this protocol;
/// in other words, the size of the table in words.
unsigned getNumWitnesses() const {
Expand Down