Skip to content

Commit

Permalink
Merge pull request ethereum#2194 from ethereum/removeerrorlabel
Browse files Browse the repository at this point in the history
Remove error label / invalid jump label.
  • Loading branch information
chriseth authored May 5, 2017
2 parents 2d89cfa + 28f10f4 commit 0582fcb
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 53 deletions.
9 changes: 2 additions & 7 deletions docs/assembly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,6 @@ As an example how this can be done in extreme cases, please see the following.
pop // We have to pop the manually pushed value here again.
}
.. note::

``invalidJumpLabel`` is a pre-defined label. Jumping to this location will always
result in an invalid jump, effectively aborting execution of the code.

Declaring Assembly-Local Variables
----------------------------------

Expand Down Expand Up @@ -699,7 +694,7 @@ The following assembly will be generated::
mstore(ret, r)
return(ret, 0x20)
}
default: { jump(invalidJumpLabel) }
default: { revert(0, 0) }
// memory allocator
function $allocate(size) -> pos {
pos := mload(0x40)
Expand Down Expand Up @@ -744,7 +739,7 @@ After the desugaring phase it looks as follows::
}
$caseDefault:
{
jump(invalidJumpLabel)
revert(0, 0)
jump($endswitch)
}
$endswitch:
Expand Down
19 changes: 0 additions & 19 deletions libsolidity/codegen/CompilerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,25 +299,6 @@ void CompilerUtils::zeroInitialiseMemoryArray(ArrayType const& _type)
m_context << Instruction::SWAP1 << Instruction::POP;
}

void CompilerUtils::memoryCopyPrecompile()
{
// Stack here: size target source

m_context.appendInlineAssembly(R"(
{
let words := div(add(len, 31), 32)
let cost := add(15, mul(3, words))
jumpi(invalidJumpLabel, iszero(call(cost, $identityContractAddress, 0, src, len, dst, len)))
}
)",
{ "len", "dst", "src" },
map<string, string> {
{ "$identityContractAddress", toString(identityContractAddress) }
}
);
m_context << Instruction::POP << Instruction::POP << Instruction::POP;
}

void CompilerUtils::memoryCopy32()
{
// Stack here: size target source
Expand Down
4 changes: 0 additions & 4 deletions libsolidity/codegen/CompilerUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ class CompilerUtils
/// Stack post: <updated_memptr>
void zeroInitialiseMemoryArray(ArrayType const& _type);

/// Uses a CALL to the identity contract to perform a memory-to-memory copy.
/// Stack pre: <size> <target> <source>
/// Stack post:
void memoryCopyPrecompile();
/// Copies full 32 byte words in memory (regions cannot overlap), i.e. may copy more than length.
/// Stack pre: <size> <target> <source>
/// Stack post:
Expand Down
2 changes: 0 additions & 2 deletions libsolidity/inlineasm/AsmCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,6 @@ class CodeTransform: public boost::static_visitor<>
{
if (_label.id == Scope::Label::unassignedLabelId)
_label.id = m_state.newLabelId();
else if (_label.id == Scope::Label::errorLabelId)
_label.id = size_t(m_state.assembly.errorTag().data());
}


Expand Down
1 change: 0 additions & 1 deletion libsolidity/inlineasm/AsmScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ struct Scope
struct Label
{
size_t id = unassignedLabelId;
static const size_t errorLabelId = -1;
static const size_t unassignedLabelId = 0;
};

Expand Down
4 changes: 0 additions & 4 deletions libsolidity/inlineasm/AsmScopeFiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ using namespace dev::solidity::assembly;
ScopeFiller::ScopeFiller(ScopeFiller::Scopes& _scopes, ErrorList& _errors):
m_scopes(_scopes), m_errors(_errors)
{
// Make the Solidity ErrorTag available to inline assembly
Scope::Label errorLabel;
errorLabel.id = Scope::Label::errorLabelId;
scope(nullptr).identifiers["invalidJumpLabel"] = errorLabel;
m_currentScope = &scope(nullptr);
}

Expand Down
2 changes: 1 addition & 1 deletion test/libsolidity/InlineAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ BOOST_AUTO_TEST_CASE(imbalanced_stack)

BOOST_AUTO_TEST_CASE(error_tag)
{
BOOST_CHECK(successAssemble("{ jump(invalidJumpLabel) }"));
CHECK_ASSEMBLE_ERROR("{ jump(invalidJumpLabel) }", DeclarationError, "Identifier not found");
}

BOOST_AUTO_TEST_CASE(designated_invalid_instruction)
Expand Down
15 changes: 0 additions & 15 deletions test/libsolidity/SolidityEndToEndTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9126,21 +9126,6 @@ BOOST_AUTO_TEST_CASE(packed_storage_overflow)
BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0x1234), u256(0), u256(0), u256(0xfffe)));
}

BOOST_AUTO_TEST_CASE(inline_assembly_invalidjumplabel)
{
char const* sourceCode = R"(
contract C {
function f() {
assembly {
jump(invalidJumpLabel)
}
}
}
)";
compileAndRun(sourceCode, 0, "C");
BOOST_CHECK(callContractFunction("f()") == encodeArgs());
}

BOOST_AUTO_TEST_CASE(contracts_separated_with_comment)
{
char const* sourceCode = R"(
Expand Down

0 comments on commit 0582fcb

Please sign in to comment.