Skip to content

Commit 12ccc59

Browse files
author
Laszlo Kindrat
committed
[mlir] Change the order of members in MLIRContext to ensure dialects are destroyed first
Currently, the dialects precede the registered operations in the context object, which means that the latter is destroyed first. At the same time, Operation::~Operation dereferences the registered operation when destroying properties, which can cause use-after-free (e.g. if a dialect owns an op). This patch fixes that by changing the order of the members so that dialects come after registered operations. Differential Revision: https://reviews.llvm.org/D151440
1 parent eb9ba24 commit 12ccc59

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

mlir/lib/IR/MLIRContext.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,6 @@ class MLIRContextImpl {
175175
/// destruction with the context.
176176
std::unique_ptr<llvm::ThreadPool> ownedThreadPool;
177177

178-
/// This is a list of dialects that are created referring to this context.
179-
/// The MLIRContext owns the objects.
180-
DenseMap<StringRef, std::unique_ptr<Dialect>> loadedDialects;
181-
DialectRegistry dialectsRegistry;
182-
183178
/// An allocator used for AbstractAttribute and AbstractType objects.
184179
llvm::BumpPtrAllocator abstractDialectSymbolAllocator;
185180

@@ -193,6 +188,12 @@ class MLIRContextImpl {
193188
/// and efficient `getRegisteredOperations` implementation.
194189
SmallVector<RegisteredOperationName, 0> sortedRegisteredOperations;
195190

191+
/// This is a list of dialects that are created referring to this context.
192+
/// The MLIRContext owns the objects. These need to be declared after the
193+
/// registered operations to ensure correct destruction order.
194+
DenseMap<StringRef, std::unique_ptr<Dialect>> loadedDialects;
195+
DialectRegistry dialectsRegistry;
196+
196197
/// A mutex used when accessing operation information.
197198
llvm::sys::SmartRWMutex<true> operationInfoMutex;
198199

0 commit comments

Comments
 (0)