Skip to content

Commit

Permalink
Show restricted instruction warning before argument mismatch issue
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Jan 8, 2018
1 parent 767052f commit 42f8875
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions libsolidity/inlineasm/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,6 @@ assembly::Expression Parser::parseExpression()
if (operation.type() == typeid(Instruction))
{
Instruction const& instr = boost::get<Instruction>(operation);
// Enforce functional notation for instructions requiring multiple arguments.
int args = instructionInfo(instr.instruction).args;
bool requireFunctionalNotation = (args > 0 || m_flavour != AsmFlavour::Loose);
if (requireFunctionalNotation && currentToken() != Token::LParen)
fatalParserError(string(
"Expected token \"(\" (\"" +
instructionNames().at(instr.instruction) +
"\" expects " +
boost::lexical_cast<string>(args) +
" arguments)"
));
// Disallow instructions returning multiple values (and DUP/SWAP) as expression.
if (
instructionInfo(instr.instruction).ret != 1 ||
Expand All @@ -276,6 +265,17 @@ assembly::Expression Parser::parseExpression()
instructionNames().at(instr.instruction) +
"\" not allowed in this context."
);
// Enforce functional notation for instructions requiring multiple arguments.
int args = instructionInfo(instr.instruction).args;
bool requireFunctionalNotation = (args > 0 || m_flavour != AsmFlavour::Loose);
if (requireFunctionalNotation && currentToken() != Token::LParen)
fatalParserError(string(
"Expected token \"(\" (\"" +
instructionNames().at(instr.instruction) +
"\" expects " +
boost::lexical_cast<string>(args) +
" arguments)"
));
}
if (currentToken() == Token::LParen)
return parseCall(std::move(operation));
Expand Down
8 changes: 4 additions & 4 deletions test/libsolidity/InlineAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,11 @@ BOOST_AUTO_TEST_CASE(no_opcodes_in_strict)
{
BOOST_CHECK(successParse("{ pop(callvalue) }"));
BOOST_CHECK(successParse("{ callvalue pop }"));
CHECK_STRICT_ERROR("{ pop(callvalue) }", ParserError, "Expected token \"(\" (\"callvalue\" expects 0 arguments)");
CHECK_STRICT_ERROR("{ pop(callvalue) }", ParserError, "Instruction \"callvalue\" not allowed in this context");
CHECK_STRICT_ERROR("{ callvalue pop }", ParserError, "Call or assignment expected");
SUCCESS_STRICT("{ pop(callvalue()) }");
BOOST_CHECK(successParse("{ switch callvalue case 0 {} }"));
CHECK_STRICT_ERROR("{ switch callvalue case 0 {} }", ParserError, "Expected token \"(\" (\"callvalue\" expects 0 arguments)");
CHECK_STRICT_ERROR("{ switch callvalue case 0 {} }", ParserError, "Instruction \"callvalue\" not allowed in this context");
}

BOOST_AUTO_TEST_CASE(no_labels_in_strict)
Expand All @@ -509,8 +509,8 @@ BOOST_AUTO_TEST_CASE(no_dup_swap_in_strict)
CHECK_STRICT_ERROR("{ swap2 }", ParserError, "Call or assignment expected.");
BOOST_CHECK(successParse("{ dup2 pop }"));
CHECK_STRICT_ERROR("{ dup2 pop }", ParserError, "Call or assignment expected.");
CHECK_PARSE_ERROR("{ switch dup1 case 0 {} }", ParserError, "Expected token \"(\" (\"dup1\" expects 1 arguments)");
CHECK_STRICT_ERROR("{ switch dup1 case 0 {} }", ParserError, "Expected token \"(\" (\"dup1\" expects 1 arguments)");
CHECK_PARSE_ERROR("{ switch dup1 case 0 {} }", ParserError, "Instruction \"dup1\" not allowed in this context");
CHECK_STRICT_ERROR("{ switch dup1 case 0 {} }", ParserError, "Instruction \"dup1\" not allowed in this context");
}

BOOST_AUTO_TEST_SUITE_END()
Expand Down

0 comments on commit 42f8875

Please sign in to comment.