Skip to content

Commit

Permalink
eof: Add test, make needed test support bytecodeFormat flag, adjust s…
Browse files Browse the repository at this point in the history
…ubcontainers tests
  • Loading branch information
rodiazet committed Nov 29, 2024
1 parent 2bae7e1 commit 363f3dd
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 7 deletions.
2 changes: 1 addition & 1 deletion test/libyul/ControlFlowGraphTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ using namespace solidity::frontend;
using namespace solidity::frontend::test;

ControlFlowGraphTest::ControlFlowGraphTest(std::string const& _filename):
TestCase(_filename)
EVMVersionRestrictedTestCase(_filename)
{
m_source = m_reader.source();
auto dialectName = m_reader.stringSetting("dialect", "evm");
Expand Down
2 changes: 1 addition & 1 deletion test/libyul/ControlFlowGraphTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct Dialect;
namespace test
{

class ControlFlowGraphTest: public solidity::frontend::test::TestCase
class ControlFlowGraphTest: public frontend::test::EVMVersionRestrictedTestCase
{
public:
static std::unique_ptr<TestCase> create(Config const& _config)
Expand Down
10 changes: 8 additions & 2 deletions test/libyul/StackLayoutGeneratorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <libyul/backends/evm/ControlFlowGraphBuilder.h>
#include <libyul/backends/evm/StackHelpers.h>
#include <libyul/backends/evm/StackLayoutGenerator.h>
#include <libyul/backends/evm/EVMDialect.h>
#include <libyul/Object.h>
#include <liblangutil/SourceReferenceFormatter.h>

Expand All @@ -45,7 +46,7 @@ using namespace solidity::frontend;
using namespace solidity::frontend::test;

StackLayoutGeneratorTest::StackLayoutGeneratorTest(std::string const& _filename):
TestCase(_filename)
EVMVersionRestrictedTestCase(_filename)
{
m_source = m_reader.source();
auto dialectName = m_reader.stringSetting("dialect", "evm");
Expand Down Expand Up @@ -229,7 +230,12 @@ TestCase::TestResult StackLayoutGeneratorTest::run(std::ostream& _stream, std::s
std::ostringstream output;

std::unique_ptr<CFG> cfg = ControlFlowGraphBuilder::build(*analysisInfo, *m_dialect, object->code()->root());
StackLayout stackLayout = StackLayoutGenerator::run(*cfg);

bool simulateFunctionsWithJumps = true;
if (auto const* evmDialect = dynamic_cast<EVMDialect const*>(m_dialect))
simulateFunctionsWithJumps = !evmDialect->eofVersion().has_value();

StackLayout stackLayout = StackLayoutGenerator::run(*cfg, simulateFunctionsWithJumps);

output << "digraph CFG {\nnodesep=0.7;\nnode[shape=box];\n\n";
StackLayoutPrinter printer{output, stackLayout};
Expand Down
2 changes: 1 addition & 1 deletion test/libyul/StackLayoutGeneratorTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct Dialect;
namespace test
{

class StackLayoutGeneratorTest: public solidity::frontend::test::TestCase
class StackLayoutGeneratorTest: public frontend::test::EVMVersionRestrictedTestCase
{
public:
static std::unique_ptr<TestCase> create(Config const& _config)
Expand Down
1 change: 0 additions & 1 deletion test/libyul/objectCompiler/eof/256_subcontainers.yul
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ object "a" {
}

// ====
// EVMVersion: >=prague
// bytecodeFormat: >=EOFv1
// ----
// Assembly:
Expand Down
84 changes: 84 additions & 0 deletions test/libyul/objectCompiler/eof/functions.yul
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
object "a" {
code {
mstore(0, fun1(calldataload(0)))

if calldataload(32) {
non_ret_fun()
}

return(0, 32)

function fun1(i) -> r {
if i {
r := 5
leave
}
r := 99
}

function non_ret_fun() {
revert(0, 0)
}
}
}

// ====
// bytecodeFormat: >=EOFv1
// ----
// Assembly:
// /* "source":74:75 */
// 0x00
// /* "source":61:76 */
// calldataload
// /* "source":56:77 */
// callf{code_section_1}
// /* "source":53:54 */
// 0x00
// /* "source":46:78 */
// mstore
// /* "source":107:109 */
// 0x20
// /* "source":94:110 */
// calldataload
// /* "source":91:128 */
// rjumpi{tag_1}
// /* "source":22:386 */
// tag_2:
// /* "source":151:153 */
// 0x20
// /* "source":148:149 */
// 0x00
// /* "source":141:154 */
// return
// /* "source":111:128 */
// tag_1:
// /* "source":113:126 */
// jumpf{code_section_2}
//
// code_section_1: assembly {
// /* "source":217:294 */
// rjumpi{tag_3}
// /* "source":203:324 */
// tag_4:
// /* "source":312:314 */
// 0x63
// /* "source":173:324 */
// retf
// /* "source":234:294 */
// tag_3:
// /* "source":257:258 */
// 0x05
// /* "source":275:280 */
// retf
// }
//
// code_section_2: assembly {
// /* "source":376:377 */
// 0x00
// /* "source":366:378 */
// dup1
// revert
// }
// Bytecode: ef000101000c020003001400090003040000000080ffff0101ffff0080ffff5f35e300015f52602035e1000460205ff3e50002e100036063e46005e45f80fd
// Opcodes: 0xEF STOP ADD ADD STOP 0xC MUL STOP SUB STOP EQ STOP MULMOD STOP SUB DIV STOP STOP STOP STOP DUP1 SELFDESTRUCT SELFDESTRUCT ADD ADD SELFDESTRUCT SELFDESTRUCT STOP DUP1 SELFDESTRUCT SELFDESTRUCT PUSH0 CALLDATALOAD CALLF 0x1 PUSH0 MSTORE PUSH1 0x20 CALLDATALOAD RJUMPI 0x4 PUSH1 0x20 PUSH0 RETURN JUMPF 0x2 RJUMPI 0x3 PUSH1 0x63 RETF PUSH1 0x5 RETF PUSH0 DUP1 REVERT
// SourceMappings: 74:1:0:-:0;61:15;56:21::i;53:1::-;46:32;107:2;94:16;91:37;22:364;151:2;148:1;141:13;111:17;113:13::i217:77:0:-:0;203:121;312:2;173:151::o;234:60::-;257:1;275:5::o376:1:0:-:0;366:12;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
object "a" {
code {
function too_many_arguments(
i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17, i18, i19, i20, i21, i22, i23, i24, i25, i26, i27, i28, i29, i30,
i31, i32, i33, i34, i35, i36, i37, i38, i39, i40, i41, i42, i43, i44, i45, i46, i47, i48, i49, i50, i51, i52, i53, i54, i55, i56, i57, i58, i59, i60,
i61, i62, i63, i64, i65, i66, i67, i68, i69, i70, i71, i72, i73, i74, i75, i76, i77, i78, i79, i80, i81, i82, i83, i84, i85, i86, i87, i88, i89, i90,
i91, i92, i93, i94, i95, i96, i97, i98, i99, i100, i101, i102, i103, i104, i105, i106, i107, i108, i109, i110, i111, i112, i113, i114, i115, i116, i117, i118, i119, i120,
i121, i122, i123, i124, i125, i126, i127, i128
)
{}

function too_many_returns()->
i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17, i18, i19, i20, i21, i22, i23, i24, i25, i26, i27, i28, i29, i30,
i31, i32, i33, i34, i35, i36, i37, i38, i39, i40, i41, i42, i43, i44, i45, i46, i47, i48, i49, i50, i51, i52, i53, i54, i55, i56, i57, i58, i59, i60,
i61, i62, i63, i64, i65, i66, i67, i68, i69, i70, i71, i72, i73, i74, i75, i76, i77, i78, i79, i80, i81, i82, i83, i84, i85, i86, i87, i88, i89, i90,
i91, i92, i93, i94, i95, i96, i97, i98, i99, i100, i101, i102, i103, i104, i105, i106, i107, i108, i109, i110, i111, i112, i113, i114, i115, i116, i117, i118, i119, i120,
i121, i122, i123, i124, i125, i126, i127, i128
{}
}
}

// ====
// bytecodeFormat: >=EOFv1
// ----
// TypeError 8534: (32-800): Too many function parameters. At most 127 parameters allowed for EOF
// TypeError 2101: (810-1569): Too many function return variables. At most 127 return variables allowed for EOF
1 change: 0 additions & 1 deletion test/libyul/yulSyntaxTests/eof/too_many_subcontainers.yul
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ object "a" {
}

// ====
// EVMVersion: >=prague
// bytecodeFormat: >=EOFv1
// ----
// SyntaxError 1305: (22-101): Too many subobjects in "a". At most 256 subobjects allowed when compiling to EOF

0 comments on commit 363f3dd

Please sign in to comment.