diff --git a/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp b/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp index 2925660207b39d..012ff73fc8e5b3 100644 --- a/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp @@ -9,6 +9,8 @@ #include "llvm/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.h" #include "llvm/ExecutionEngine/Orc/LookupAndRecordAddrs.h" +#include + namespace llvm { namespace orc { @@ -32,7 +34,8 @@ class EPCGenericJITLinkMemoryManager::Alloc MutableArrayRef getWorkingMemory(ProtectionFlags Seg) override { auto I = Segs.find(Seg); assert(I != Segs.end() && "No allocation for seg"); - return {I->second.WorkingMem, I->second.ContentSize}; + assert(I->second.ContentSize <= std::numeric_limits::max()); + return {I->second.WorkingMem, static_cast(I->second.ContentSize)}; } JITTargetAddress getTargetMemory(ProtectionFlags Seg) override { @@ -45,13 +48,14 @@ class EPCGenericJITLinkMemoryManager::Alloc char *WorkingMem = WorkingBuffer.get(); tpctypes::FinalizeRequest FR; for (auto &KV : Segs) { + assert(KV.second.ContentSize <= std::numeric_limits::max()); FR.push_back(tpctypes::SegFinalizeRequest{ tpctypes::toWireProtectionFlags( static_cast(KV.first)), KV.second.TargetAddr, alignTo(KV.second.ContentSize + KV.second.ZeroFillSize, Parent.EPC.getPageSize()), - {WorkingMem, KV.second.ContentSize}}); + {WorkingMem, static_cast(KV.second.ContentSize)}}); WorkingMem += KV.second.ContentSize; } Parent.EPC.callSPSWrapperAsync( diff --git a/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp index 4d9b01b0c2d6df..186aa75b4966c5 100644 --- a/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp @@ -13,6 +13,8 @@ #include "llvm/Support/Memory.h" #include "llvm/Testing/Support/Error.h" +#include + using namespace llvm; using namespace llvm::orc; using namespace llvm::orc::shared; @@ -44,8 +46,9 @@ testFinalize(const char *ArgData, size_t ArgSize) { memcpy(Mem, Seg.Content.data(), Seg.Content.size()); memset(Mem + Seg.Content.size(), 0, Seg.Size - Seg.Content.size()); + assert(Seg.Size <= std::numeric_limits::max()); if (auto EC = sys::Memory::protectMappedMemory( - {Mem, Seg.Size}, + {Mem, static_cast(Seg.Size)}, tpctypes::fromWireProtectionFlags(Seg.Prot))) return errorCodeToError(EC); if (Seg.Prot & tpctypes::WPF_Exec)