Skip to content

Commit 4340ffd

Browse files
committed
eof: Make "jump too far" error testable. Add tests.
1 parent b27bb82 commit 4340ffd

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

libevmasm/Assembly.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,14 @@ LinkerObject const& Assembly::assembleEOF() const
16601660

16611661
ptrdiff_t const relativeJumpOffset = static_cast<ptrdiff_t>(tagPos) - (static_cast<ptrdiff_t>(refPos) + 2);
16621662
// This cannot happen in practice because we'll run into section size limit first.
1663-
solAssert(-0x8000 <= relativeJumpOffset && relativeJumpOffset <= 0x7FFF, "Relative jump too far");
1663+
if (!(-0x8000 <= relativeJumpOffset && relativeJumpOffset <= 0x7FFF))
1664+
// TODO: Include source location. Note that origin locations we have in debug data are
1665+
// not usable for error reporting when compiling pure Yul because they point at the optimized source.
1666+
throw Error(
1667+
2703_error,
1668+
Error::Type::CodeGenerationError,
1669+
"Relative jump too far"
1670+
);
16641671
solAssert(relativeJumpOffset < -2 || 0 <= relativeJumpOffset, "Relative jump offset into immediate argument.");
16651672
setBigEndianUint16(ret.bytecode, refPos, static_cast<size_t>(static_cast<uint16_t>(relativeJumpOffset)));
16661673
}

0 commit comments

Comments
 (0)