From 396a826d791e63322cd4f47f116412d3e30ea5fc Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 31 Jan 2024 19:08:12 +0000 Subject: [PostEmscripten] Fix calcSegmentOffsets for large offsets (#6260) Specifically offsets larger than 2^32 which were being interpreted misinterpreted here as very large int64_t values. --- src/passes/PostEmscripten.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/passes/PostEmscripten.cpp b/src/passes/PostEmscripten.cpp index 6dc32eaa8..b7d3e9f91 100644 --- a/src/passes/PostEmscripten.cpp +++ b/src/passes/PostEmscripten.cpp @@ -95,12 +95,11 @@ static void calcSegmentOffsets(Module& wasm, return; } } - auto it = offsets.find(curr->segment); - if (it != offsets.end()) { + if (offsets.find(curr->segment) != offsets.end()) { Fatal() << "Cannot get offset of passive segment initialized " "multiple times"; } - offsets[curr->segment] = dest->value.getInteger(); + offsets[curr->segment] = dest->value.getUnsigned(); } } searcher(passiveOffsets); searcher.walkModule(&wasm); @@ -317,7 +316,7 @@ struct PostEmscripten : public Pass { // The first operand is the function pointer index, which must be // constant if we are to optimize it statically. if (auto* index = curr->operands[0]->dynCast()) { - size_t indexValue = index->value.getInteger(); + size_t indexValue = index->value.getUnsigned(); if (indexValue >= flatTable.names.size()) { // UB can lead to indirect calls to invalid pointers. return; -- cgit v1.2.3