From dbbdcc66e61a5a5d36a4fd55087b22e145a1c3e4 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 24 Jun 2017 12:56:21 +0100 Subject: [PATCH] LLL: fix redefinitions on some compilers --- liblll/CodeFragment.cpp | 6 +++++- test/liblll/EndToEndTest.cpp | 37 +++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/liblll/CodeFragment.cpp b/liblll/CodeFragment.cpp index 7496fe83e..56c1e26af 100644 --- a/liblll/CodeFragment.cpp +++ b/liblll/CodeFragment.cpp @@ -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) { diff --git a/test/liblll/EndToEndTest.cpp b/test/liblll/EndToEndTest.cpp index 3037b14bd..70a918077 100644 --- a/test/liblll/EndToEndTest.cpp +++ b/test/liblll/EndToEndTest.cpp @@ -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"( @@ -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) {