Skip to content

Commit 02b4620

Browse files
committed
[ORC] Static cast more uint64_t to size_t
These instances don't have an obvious way to fail nicely so I've just asserted they are within range. Fixes the Arm 32 bit builds.
1 parent 6fe2beb commit 02b4620

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "llvm/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.h"
1010
#include "llvm/ExecutionEngine/Orc/LookupAndRecordAddrs.h"
1111

12+
#include <limits>
13+
1214
namespace llvm {
1315
namespace orc {
1416

@@ -32,7 +34,8 @@ class EPCGenericJITLinkMemoryManager::Alloc
3234
MutableArrayRef<char> getWorkingMemory(ProtectionFlags Seg) override {
3335
auto I = Segs.find(Seg);
3436
assert(I != Segs.end() && "No allocation for seg");
35-
return {I->second.WorkingMem, I->second.ContentSize};
37+
assert(I->second.ContentSize <= std::numeric_limits<size_t>::max());
38+
return {I->second.WorkingMem, static_cast<size_t>(I->second.ContentSize)};
3639
}
3740

3841
JITTargetAddress getTargetMemory(ProtectionFlags Seg) override {
@@ -45,13 +48,14 @@ class EPCGenericJITLinkMemoryManager::Alloc
4548
char *WorkingMem = WorkingBuffer.get();
4649
tpctypes::FinalizeRequest FR;
4750
for (auto &KV : Segs) {
51+
assert(KV.second.ContentSize <= std::numeric_limits<size_t>::max());
4852
FR.push_back(tpctypes::SegFinalizeRequest{
4953
tpctypes::toWireProtectionFlags(
5054
static_cast<sys::Memory::ProtectionFlags>(KV.first)),
5155
KV.second.TargetAddr,
5256
alignTo(KV.second.ContentSize + KV.second.ZeroFillSize,
5357
Parent.EPC.getPageSize()),
54-
{WorkingMem, KV.second.ContentSize}});
58+
{WorkingMem, static_cast<size_t>(KV.second.ContentSize)}});
5559
WorkingMem += KV.second.ContentSize;
5660
}
5761
Parent.EPC.callSPSWrapperAsync<shared::SPSOrcTargetProcessFinalize>(

llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "llvm/Support/Memory.h"
1414
#include "llvm/Testing/Support/Error.h"
1515

16+
#include <limits>
17+
1618
using namespace llvm;
1719
using namespace llvm::orc;
1820
using namespace llvm::orc::shared;
@@ -44,8 +46,9 @@ testFinalize(const char *ArgData, size_t ArgSize) {
4446
memcpy(Mem, Seg.Content.data(), Seg.Content.size());
4547
memset(Mem + Seg.Content.size(), 0,
4648
Seg.Size - Seg.Content.size());
49+
assert(Seg.Size <= std::numeric_limits<size_t>::max());
4750
if (auto EC = sys::Memory::protectMappedMemory(
48-
{Mem, Seg.Size},
51+
{Mem, static_cast<size_t>(Seg.Size)},
4952
tpctypes::fromWireProtectionFlags(Seg.Prot)))
5053
return errorCodeToError(EC);
5154
if (Seg.Prot & tpctypes::WPF_Exec)

0 commit comments

Comments
 (0)