From: Lang Hames Date: Tue, 12 Oct 2021 16:48:29 +0000 (-0700) Subject: [Support][ORC] Add an explicit release operation to OwningMemoryBlock. X-Git-Tag: upstream/15.0.7~28832 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bbc2fc548b43806f2c2a2180b696127f7a680050;p=platform%2Fupstream%2Fllvm.git [Support][ORC] Add an explicit release operation to OwningMemoryBlock. This gives OwningMemoryBlock clients a way to check for errors on release. rdar://84127175 --- diff --git a/llvm/include/llvm/Support/Memory.h b/llvm/include/llvm/Support/Memory.h index a40ca9f..d7d6037 100644 --- a/llvm/include/llvm/Support/Memory.h +++ b/llvm/include/llvm/Support/Memory.h @@ -148,13 +148,22 @@ namespace sys { return *this; } ~OwningMemoryBlock() { - Memory::releaseMappedMemory(M); + if (M.base()) + Memory::releaseMappedMemory(M); } void *base() const { return M.base(); } /// The size as it was allocated. This is always greater or equal to the /// size that was originally requested. size_t allocatedSize() const { return M.allocatedSize(); } MemoryBlock getMemoryBlock() const { return M; } + std::error_code release() { + std::error_code EC; + if (M.base()) { + EC = Memory::releaseMappedMemory(M); + M = MemoryBlock(); + } + return EC; + } private: MemoryBlock M; }; diff --git a/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp index e7e4e56..f2b157e 100644 --- a/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp @@ -68,8 +68,7 @@ public: } auto MB = std::move(I->second); Blocks.erase(I); - auto MBToRelease = MB.getMemoryBlock(); - if (auto EC = sys::Memory::releaseMappedMemory(MBToRelease)) + if (auto EC = MB.release()) Err = joinErrors(std::move(Err), errorCodeToError(EC)); } return Err;