Tests for labels with stack information.

This commit is contained in:
chriseth 2017-02-14 18:14:40 +01:00
parent 6bfd894f46
commit fd62adebf3
2 changed files with 37 additions and 0 deletions

View File

@ -200,6 +200,11 @@ BOOST_AUTO_TEST_CASE(blocks)
BOOST_CHECK(successParse("{ let x := 7 { let y := 3 } { let z := 2 } }"));
}
BOOST_AUTO_TEST_CASE(labels_with_stack_info)
{
BOOST_CHECK(successParse("{ x[-1]: y[a]: z[d, e]: h[100]: g[]: }"));
}
BOOST_AUTO_TEST_CASE(function_definitions)
{
BOOST_CHECK(successParse("{ function f() { } function g(a) -> (x) { } }"));
@ -244,6 +249,11 @@ BOOST_AUTO_TEST_CASE(print_label)
parsePrintCompare("{\n loop:\n jump(loop)\n}");
}
BOOST_AUTO_TEST_CASE(print_label_with_stack)
{
parsePrintCompare("{\n loop[x, y]:\n other[-2]:\n third[10]:\n}");
}
BOOST_AUTO_TEST_CASE(print_assignments)
{
parsePrintCompare("{\n let x := mul(2, 3)\n 7\n =: x\n x := add(1, 2)\n}");

View File

@ -7418,6 +7418,33 @@ BOOST_AUTO_TEST_CASE(inline_assembly_function_access)
BOOST_CHECK(callContractFunction("x()") == encodeArgs(u256(10)));
}
BOOST_AUTO_TEST_CASE(inline_assembly_labels_with_stack_info)
{
char const* sourceCode = R"(
contract C {
function f(uint y) {
assembly {
y 7
jump(fun)
exit[-1]:
y add
0 mstore
return(0, 0x20)
fun:
{
entry[a, b]:
a := div(a, b)
pop
jump(exit)
}
}
}
}
)";
compileAndRun(sourceCode, 0, "C");
BOOST_CHECK(callContractFunction("f(uint256)", u256(15)) == encodeArgs(15 / 7 + 15));
}
BOOST_AUTO_TEST_CASE(index_access_with_type_conversion)
{
// Test for a bug where higher order bits cleanup was not done for array index access.