Skip to content

Commit

Permalink
LLL: fix redefinitions on some compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Jun 24, 2017
1 parent b83f77e commit dbbdcc6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
6 changes: 5 additions & 1 deletion liblll/CodeFragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
}
else if (ii == 2)
if (_t.size() == 3)
_s.defs[n] = CodeFragment(i, _s);
{
/// NOTE: some compilers could do the assignment first if this is done in a single line
CodeFragment code = CodeFragment(i, _s);
_s.defs[n] = code;
}
else
for (auto const& j: i)
{
Expand Down
37 changes: 26 additions & 11 deletions test/liblll/EndToEndTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,32 @@ BOOST_AUTO_TEST_CASE(panic)
BOOST_REQUIRE(m_output.empty());
}

BOOST_AUTO_TEST_CASE(macro_zeroarg)
{
char const* sourceCode = R"(
(returnlll
(seq
(def 'zeroarg () (seq (mstore 0 0x1234) (return 0 32)))
(zeroarg)))
)";
compileAndRun(sourceCode);
BOOST_CHECK(callFallback() == encodeArgs(u256(0x1234)));
}

BOOST_AUTO_TEST_CASE(macros)
{
char const* sourceCode = R"(
(returnlll
(seq
(def 'x 1)
(def 'y () { (def 'x (+ x 2)) })
(y)
(return x)))
)";
compileAndRun(sourceCode);
BOOST_CHECK(callFallback() == encodeArgs(u256(3)));
}

BOOST_AUTO_TEST_CASE(variables)
{
char const* sourceCode = R"(
Expand Down Expand Up @@ -361,17 +387,6 @@ BOOST_AUTO_TEST_CASE(assembly_codecopy)
BOOST_CHECK(callFallback() == encodeArgs(string("abcdef")));
}

BOOST_AUTO_TEST_CASE(zeroarg_macro)
{
char const* sourceCode = R"(
(returnlll
(seq
(def 'zeroarg () (seq (mstore 0 0x1234) (return 0 32)))
(zeroarg)))
)";
compileAndRun(sourceCode);
BOOST_CHECK(callFallback() == encodeArgs(u256(0x1234)));
}

BOOST_AUTO_TEST_CASE(keccak256_32bytes)
{
Expand Down

0 comments on commit dbbdcc6

Please sign in to comment.