Review comments.

This commit is contained in:
chriseth 2017-04-11 19:24:38 +02:00
parent 83bf34c571
commit 34717838da
4 changed files with 41 additions and 2 deletions

View File

@ -270,7 +270,8 @@ void CompilerContext::appendInlineAssembly(
identifierAccess.resolve = [&]( identifierAccess.resolve = [&](
assembly::Identifier const& _identifier, assembly::Identifier const& _identifier,
assembly::IdentifierContext assembly::IdentifierContext
) { )
{
auto it = std::find(_localVariables.begin(), _localVariables.end(), _identifier.name); auto it = std::find(_localVariables.begin(), _localVariables.end(), _identifier.name);
return it == _localVariables.end() ? size_t(-1) : 1; return it == _localVariables.end() ? size_t(-1) : 1;
}; };
@ -278,7 +279,8 @@ void CompilerContext::appendInlineAssembly(
assembly::Identifier const& _identifier, assembly::Identifier const& _identifier,
assembly::IdentifierContext _context, assembly::IdentifierContext _context,
eth::Assembly& _assembly eth::Assembly& _assembly
) { )
{
auto it = std::find(_localVariables.begin(), _localVariables.end(), _identifier.name); auto it = std::find(_localVariables.begin(), _localVariables.end(), _identifier.name);
solAssert(it != _localVariables.end(), ""); solAssert(it != _localVariables.end(), "");
unsigned stackDepth = _localVariables.end() - it; unsigned stackDepth = _localVariables.end() - it;

View File

@ -538,6 +538,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly)
solAssert(!!decl, ""); solAssert(!!decl, "");
if (_context == assembly::IdentifierContext::RValue) if (_context == assembly::IdentifierContext::RValue)
{ {
int const depositBefore = _assembly.deposit();
solAssert(!!decl->type(), "Type of declaration required but not yet determined."); solAssert(!!decl->type(), "Type of declaration required but not yet determined.");
if (FunctionDefinition const* functionDef = dynamic_cast<FunctionDefinition const*>(decl)) if (FunctionDefinition const* functionDef = dynamic_cast<FunctionDefinition const*>(decl))
{ {
@ -591,6 +592,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly)
} }
else else
solAssert(false, "Invalid declaration type."); solAssert(false, "Invalid declaration type.");
solAssert(_assembly.deposit() - depositBefore == ref->second.valueSize, "");
} }
else else
{ {

View File

@ -342,6 +342,11 @@ BOOST_AUTO_TEST_CASE(magic_variables)
BOOST_CHECK(successAssemble("{ let ecrecover := 1 ecrecover pop }")); BOOST_CHECK(successAssemble("{ let ecrecover := 1 ecrecover pop }"));
} }
BOOST_AUTO_TEST_CASE(stack_variables)
{
BOOST_CHECK(successAssemble("{ let y := 3 { 2 { let x := y } pop} }"));
}
BOOST_AUTO_TEST_CASE(imbalanced_stack) BOOST_AUTO_TEST_CASE(imbalanced_stack)
{ {
BOOST_CHECK(successAssemble("{ 1 2 mul pop }", false)); BOOST_CHECK(successAssemble("{ 1 2 mul pop }", false));

View File

@ -5078,6 +5078,36 @@ BOOST_AUTO_TEST_CASE(inline_assembly_storage_in_modifiers)
CHECK_ERROR(text, DeclarationError, "Variable not found or variable not lvalue."); CHECK_ERROR(text, DeclarationError, "Variable not found or variable not lvalue.");
} }
BOOST_AUTO_TEST_CASE(inline_assembly_constant_assign)
{
char const* text = R"(
contract test {
uint constant x = 1;
function f() {
assembly {
x := 2
}
}
}
)";
CHECK_ERROR(text, DeclarationError, "Variable not found or variable not lvalue.");
}
BOOST_AUTO_TEST_CASE(inline_assembly_constant_access)
{
char const* text = R"(
contract test {
uint constant x = 1;
function f() {
assembly {
let y := x
}
}
}
)";
CHECK_ERROR(text, TypeError, "Constant variables not yet implemented for inline assembly");
}
BOOST_AUTO_TEST_CASE(invalid_mobile_type) BOOST_AUTO_TEST_CASE(invalid_mobile_type)
{ {
char const* text = R"( char const* text = R"(