mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Enforce that FileUnit + LoadedFile have trivial destructors
We already do this for other ASTContext-allocated types (see Decl.cpp). This will prevent the sort of mistakes in the previous two commits. Note that if any particular subclass of FileUnit wants to have its destructor run, it can opt into that manually using ASTContext::addDestructorCleanup. SourceFile and BuiltinUnit both do this. But we generally don't /want/ to do this if we can avoid it because it adds to compiler teardown time.
This commit is contained in:
@@ -644,7 +644,10 @@ static inline unsigned alignOfFileUnit();
|
||||
/// FileUnit is an abstract base class; its subclasses represent different
|
||||
/// sorts of containers that can each provide a set of decls, e.g. a source
|
||||
/// file. A module can contain several file-units.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
|
||||
class FileUnit : public DeclContext {
|
||||
#pragma clang diagnostic pop
|
||||
virtual void anchor();
|
||||
|
||||
// FIXME: Stick this in a PointerIntPair.
|
||||
@@ -655,8 +658,6 @@ protected:
|
||||
: DeclContext(DeclContextKind::FileUnit, &M), Kind(kind) {
|
||||
}
|
||||
|
||||
virtual ~FileUnit() = default;
|
||||
|
||||
public:
|
||||
FileUnitKind getKind() const {
|
||||
return Kind;
|
||||
@@ -891,13 +892,7 @@ private:
|
||||
// Make placement new and vanilla new/delete illegal for FileUnits.
|
||||
void *operator new(size_t Bytes) throw() = delete;
|
||||
void *operator new(size_t Bytes, void *Mem) throw() = delete;
|
||||
|
||||
protected:
|
||||
// Unfortunately we can't remove this altogether because the virtual
|
||||
// destructor requires it to be accessible.
|
||||
void operator delete(void *Data) throw() {
|
||||
llvm_unreachable("Don't use operator delete on a SourceFile");
|
||||
}
|
||||
void operator delete(void *Data) throw() = delete;
|
||||
|
||||
public:
|
||||
// Only allow allocation of FileUnits using the allocator in ASTContext
|
||||
@@ -1380,9 +1375,11 @@ public:
|
||||
};
|
||||
|
||||
/// Represents an externally-loaded file of some kind.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
|
||||
class LoadedFile : public FileUnit {
|
||||
#pragma clang diagnostic pop
|
||||
protected:
|
||||
~LoadedFile() = default;
|
||||
LoadedFile(FileUnitKind Kind, ModuleDecl &M) noexcept
|
||||
: FileUnit(Kind, M) {
|
||||
assert(classof(this) && "invalid kind");
|
||||
|
||||
Reference in New Issue
Block a user