mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Delete the non-placement operator new/delete in the SILAllocated CRTP base so that the compiler saves us from accidentally allocating and leaking SILInstructions on the main heap instead of the owning SILModule's BPA. Swift SVN r5468
47 lines
1.5 KiB
C++
47 lines
1.5 KiB
C++
//===--- SILAllocated.h - Defines the SILAllocated class --------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_SIL_SILALLOCATED_H
|
|
#define SWIFT_SIL_SILALLOCATED_H
|
|
|
|
#include "swift/Basic/LLVM.h"
|
|
|
|
namespace swift {
|
|
class SILModule;
|
|
|
|
/// SILAllocated - This class enforces that derived classes are allocated out of
|
|
/// the SILModule bump pointer allocator.
|
|
template <typename DERIVED>
|
|
class SILAllocated {
|
|
public:
|
|
/// Disable non-placement new.
|
|
void *operator new(size_t) = delete;
|
|
void *operator new[](size_t) = delete;
|
|
|
|
/// Disable non-placement delete.
|
|
void operator delete(void *) = delete;
|
|
void operator delete[](void *) = delete;
|
|
|
|
/// Custom version of 'new' that uses the SILModule's BumpPtrAllocator with
|
|
/// precise alignment knowledge. This is templated on the allocator type so
|
|
/// that this doesn't require including SILModule.h.
|
|
template <typename ContextTy>
|
|
void *operator new(size_t Bytes, const ContextTy &C,
|
|
size_t Alignment = alignof(DERIVED)) {
|
|
return C.allocate(Bytes, Alignment);
|
|
}
|
|
};
|
|
|
|
} // end swift namespace
|
|
|
|
#endif
|