Control flow graph for Yul.

This commit is contained in:
Daniel Kirchner
2021-07-15 15:24:12 +02:00
parent f82da14a3a
commit f3707f2ab0
24 changed files with 2019 additions and 17 deletions
+2
View File
@@ -126,6 +126,8 @@ set(libyul_sources
libyul/Common.cpp
libyul/Common.h
libyul/CompilabilityChecker.cpp
libyul/ControlFlowGraphTest.cpp
libyul/ControlFlowGraphTest.h
libyul/EVMCodeTransformTest.cpp
libyul/EVMCodeTransformTest.h
libyul/EwasmTranslationTest.cpp
+16 -14
View File
@@ -25,6 +25,7 @@
#include <test/libsolidity/SyntaxTest.h>
#include <test/libsolidity/SemanticTest.h>
#include <test/libsolidity/SMTCheckerTest.h>
#include <test/libyul/ControlFlowGraphTest.h>
#include <test/libyul/EVMCodeTransformTest.h>
#include <test/libyul/EwasmTranslationTest.h>
#include <test/libyul/YulOptimizerTest.h>
@@ -55,20 +56,21 @@ struct Testsuite
Testsuite const g_interactiveTestsuites[] = {
/*
Title Path Subpath SMT NeedsVM Creator function */
{"Ewasm Translation", "libyul", "ewasmTranslationTests",false,false, &yul::test::EwasmTranslationTest::create},
{"Yul Optimizer", "libyul", "yulOptimizerTests", false, false, &yul::test::YulOptimizerTest::create},
{"Yul Interpreter", "libyul", "yulInterpreterTests", false, false, &yul::test::YulInterpreterTest::create},
{"Yul Object Compiler", "libyul", "objectCompiler", false, false, &yul::test::ObjectCompilerTest::create},
{"Function Side Effects","libyul", "functionSideEffects", false, false, &yul::test::FunctionSideEffects::create},
{"Yul Syntax", "libyul", "yulSyntaxTests", false, false, &yul::test::SyntaxTest::create},
{"EVM Code Transform", "libyul", "evmCodeTransform", false, false, &yul::test::EVMCodeTransformTest::create, {"nooptions"}},
{"Syntax", "libsolidity", "syntaxTests", false, false, &SyntaxTest::create},
{"Error Recovery", "libsolidity", "errorRecoveryTests", false, false, &SyntaxTest::createErrorRecovery},
{"Semantic", "libsolidity", "semanticTests", false, true, &SemanticTest::create},
{"JSON AST", "libsolidity", "ASTJSON", false, false, &ASTJSONTest::create},
{"JSON ABI", "libsolidity", "ABIJson", false, false, &ABIJsonTest::create},
{"SMT Checker", "libsolidity", "smtCheckerTests", true, false, &SMTCheckerTest::create},
{"Gas Estimates", "libsolidity", "gasTests", false, false, &GasTest::create}
{"Ewasm Translation", "libyul", "ewasmTranslationTests", false, false, &yul::test::EwasmTranslationTest::create},
{"Yul Optimizer", "libyul", "yulOptimizerTests", false, false, &yul::test::YulOptimizerTest::create},
{"Yul Interpreter", "libyul", "yulInterpreterTests", false, false, &yul::test::YulInterpreterTest::create},
{"Yul Object Compiler", "libyul", "objectCompiler", false, false, &yul::test::ObjectCompilerTest::create},
{"Yul Control Flow Graph", "libyul", "yulControlFlowGraph", false, false, &yul::test::ControlFlowGraphTest::create},
{"Function Side Effects", "libyul", "functionSideEffects", false, false, &yul::test::FunctionSideEffects::create},
{"Yul Syntax", "libyul", "yulSyntaxTests", false, false, &yul::test::SyntaxTest::create},
{"EVM Code Transform", "libyul", "evmCodeTransform", false, false, &yul::test::EVMCodeTransformTest::create, {"nooptions"}},
{"Syntax", "libsolidity", "syntaxTests", false, false, &SyntaxTest::create},
{"Error Recovery", "libsolidity", "errorRecoveryTests", false, false, &SyntaxTest::createErrorRecovery},
{"Semantic", "libsolidity", "semanticTests", false, true, &SemanticTest::create},
{"JSON AST", "libsolidity", "ASTJSON", false, false, &ASTJSONTest::create},
{"JSON ABI", "libsolidity", "ABIJson", false, false, &ABIJsonTest::create},
{"SMT Checker", "libsolidity", "smtCheckerTests", true, false, &SMTCheckerTest::create},
{"Gas Estimates", "libsolidity", "gasTests", false, false, &GasTest::create}
};
}
+273
View File
@@ -0,0 +1,273 @@
/*
This file is part of solidity.
solidity is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
solidity is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
// SPDX-License-Identifier: GPL-3.0
#include <test/libyul/ControlFlowGraphTest.h>
#include <test/libyul/Common.h>
#include <test/Common.h>
#include <libyul/backends/evm/ControlFlowGraph.h>
#include <libyul/backends/evm/ControlFlowGraphBuilder.h>
#include <libyul/Object.h>
#include <liblangutil/SourceReferenceFormatter.h>
#include <libsolutil/AnsiColorized.h>
#include <libsolutil/Visitor.h>
#ifdef ISOLTEST
#include <boost/process.hpp>
#endif
using namespace solidity;
using namespace solidity::util;
using namespace solidity::langutil;
using namespace solidity::yul;
using namespace solidity::yul::test;
using namespace solidity::frontend;
using namespace solidity::frontend::test;
using namespace std;
ControlFlowGraphTest::ControlFlowGraphTest(string const& _filename):
TestCase(_filename)
{
m_source = m_reader.source();
auto dialectName = m_reader.stringSetting("dialect", "evm");
m_dialect = &dialect(dialectName, solidity::test::CommonOptions::get().evmVersion());
m_expectation = m_reader.simpleExpectations();
}
namespace
{
static std::string stackSlotToString(StackSlot const& _slot)
{
return std::visit(util::GenericVisitor{
[](FunctionCallReturnLabelSlot const& _ret) -> std::string { return "RET[" + _ret.call.get().functionName.name.str() + "]"; },
[](FunctionReturnLabelSlot const&) -> std::string { return "RET"; },
[](VariableSlot const& _var) { return _var.variable.get().name.str(); },
[](LiteralSlot const& _lit) { return util::toCompactHexWithPrefix(_lit.value); },
[](TemporarySlot const& _tmp) -> std::string { return "TMP[" + _tmp.call.get().functionName.name.str() + ", " + std::to_string(_tmp.index) + "]"; },
[](JunkSlot const&) -> std::string { return "JUNK"; }
}, _slot);
}
static std::string stackToString(Stack const& _stack)
{
std::string result("[ ");
for (auto const& slot: _stack)
result += stackSlotToString(slot) + ' ';
result += ']';
return result;
}
static std::string variableSlotToString(VariableSlot const& _slot)
{
return _slot.variable.get().name.str();
}
}
class ControlFlowGraphPrinter
{
public:
ControlFlowGraphPrinter(std::ostream& _stream):
m_stream(_stream)
{
}
void operator()(CFG::BasicBlock const& _block, bool _isMainEntry = true)
{
if (_isMainEntry)
{
m_stream << "Entry [label=\"Entry\"];\n";
m_stream << "Entry -> Block" << getBlockId(_block) << ";\n";
}
while (!m_blocksToPrint.empty())
{
CFG::BasicBlock const* block = *m_blocksToPrint.begin();
m_blocksToPrint.erase(m_blocksToPrint.begin());
printBlock(*block);
}
}
void operator()(
CFG::FunctionInfo const& _info
)
{
m_stream << "FunctionEntry_" << _info.function.name.str() << "_" << getBlockId(*_info.entry) << " [label=\"";
m_stream << "function " << _info.function.name.str() << "(";
m_stream << joinHumanReadable(_info.parameters | ranges::views::transform(variableSlotToString));
m_stream << ")";
if (!_info.returnVariables.empty())
{
m_stream << " -> ";
m_stream << joinHumanReadable(_info.returnVariables | ranges::views::transform(variableSlotToString));
}
m_stream << "\"];\n";
m_stream << "FunctionEntry_" << _info.function.name.str() << "_" << getBlockId(*_info.entry) << " -> Block" << getBlockId(*_info.entry) << ";\n";
(*this)(*_info.entry, false);
}
private:
void printBlock(CFG::BasicBlock const& _block)
{
m_stream << "Block" << getBlockId(_block) << " [label=\"\\\n";
// Verify that the entries of this block exit into this block.
for (auto const& entry: _block.entries)
std::visit(util::GenericVisitor{
[&](CFG::BasicBlock::Jump const& _jump)
{
soltestAssert(_jump.target == &_block, "Invalid control flow graph.");
},
[&](CFG::BasicBlock::ConditionalJump const& _conditionalJump)
{
soltestAssert(
_conditionalJump.zero == &_block || _conditionalJump.nonZero == &_block,
"Invalid control flow graph."
);
},
[&](auto const&)
{
soltestAssert(false, "Invalid control flow graph.");
}
}, entry->exit);
for (auto const& operation: _block.operations)
{
std::visit(util::GenericVisitor{
[&](CFG::FunctionCall const& _call) {
m_stream << _call.function.get().name.str() << ": ";
},
[&](CFG::BuiltinCall const& _call) {
m_stream << _call.functionCall.get().functionName.name.str() << ": ";
},
[&](CFG::Assignment const& _assignment) {
m_stream << "Assignment(";
m_stream << joinHumanReadable(_assignment.variables | ranges::views::transform(variableSlotToString));
m_stream << "): ";
}
}, operation.operation);
m_stream << stackToString(operation.input) << " => " << stackToString(operation.output) << "\\l\\\n";
}
m_stream << "\"];\n";
std::visit(util::GenericVisitor{
[&](CFG::BasicBlock::MainExit const&)
{
m_stream << "Block" << getBlockId(_block) << "Exit [label=\"MainExit\"];\n";
m_stream << "Block" << getBlockId(_block) << " -> Block" << getBlockId(_block) << "Exit;\n";
},
[&](CFG::BasicBlock::Jump const& _jump)
{
m_stream << "Block" << getBlockId(_block) << " -> Block" << getBlockId(_block) << "Exit [arrowhead=none];\n";
m_stream << "Block" << getBlockId(_block) << "Exit [label=\"";
if (_jump.backwards)
m_stream << "Backwards";
m_stream << "Jump\" shape=oval];\n";
m_stream << "Block" << getBlockId(_block) << "Exit -> Block" << getBlockId(*_jump.target) << ";\n";
},
[&](CFG::BasicBlock::ConditionalJump const& _conditionalJump)
{
m_stream << "Block" << getBlockId(_block) << " -> Block" << getBlockId(_block) << "Exit;\n";
m_stream << "Block" << getBlockId(_block) << "Exit [label=\"{ ";
m_stream << stackSlotToString(_conditionalJump.condition);
m_stream << "| { <0> Zero | <1> NonZero }}\" shape=Mrecord];\n";
m_stream << "Block" << getBlockId(_block);
m_stream << "Exit:0 -> Block" << getBlockId(*_conditionalJump.zero) << ";\n";
m_stream << "Block" << getBlockId(_block);
m_stream << "Exit:1 -> Block" << getBlockId(*_conditionalJump.nonZero) << ";\n";
},
[&](CFG::BasicBlock::FunctionReturn const& _return)
{
m_stream << "Block" << getBlockId(_block) << "Exit [label=\"FunctionReturn[" << _return.info->function.name.str() << "]\"];\n";
m_stream << "Block" << getBlockId(_block) << " -> Block" << getBlockId(_block) << "Exit;\n";
},
[&](CFG::BasicBlock::Terminated const&)
{
m_stream << "Block" << getBlockId(_block) << "Exit [label=\"Terminated\"];\n";
m_stream << "Block" << getBlockId(_block) << " -> Block" << getBlockId(_block) << "Exit;\n";
}
}, _block.exit);
m_stream << "\n";
}
size_t getBlockId(CFG::BasicBlock const& _block)
{
if (size_t* id = util::valueOrNullptr(m_blockIds, &_block))
return *id;
size_t id = m_blockIds[&_block] = m_blockCount++;
m_blocksToPrint.emplace_back(&_block);
return id;
}
std::ostream& m_stream;
std::map<CFG::BasicBlock const*, size_t> m_blockIds;
size_t m_blockCount = 0;
std::list<CFG::BasicBlock const*> m_blocksToPrint;
};
TestCase::TestResult ControlFlowGraphTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
{
ErrorList errors;
auto [object, analysisInfo] = parse(m_source, *m_dialect, errors);
if (!object || !analysisInfo || !Error::containsOnlyWarnings(errors))
{
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing source." << endl;
return TestResult::FatalError;
}
std::ostringstream output;
std::unique_ptr<CFG> cfg = ControlFlowGraphBuilder::build(*analysisInfo, *m_dialect, *object->code);
output << "digraph CFG {\nnodesep=0.7;\nnode[shape=box];\n\n";
ControlFlowGraphPrinter printer{output};
printer(*cfg->entry);
for (auto function: cfg->functions)
printer(cfg->functionInfo.at(function));
output << "}\n";
m_obtainedResult = output.str();
auto result = checkResult(_stream, _linePrefix, _formatted);
#ifdef ISOLTEST
char* graphDisplayer = nullptr;
// The environment variables specify an optional command that will receive the graph encoded in DOT through stdin.
// Examples for suitable commands are ``dot -Tx11:cairo`` or ``xdot -``.
if (result == TestResult::Failure)
// ISOLTEST_DISPLAY_GRAPHS_ON_FAILURE_COMMAND will run on all failing tests (intended for use during modifications).
graphDisplayer = getenv("ISOLTEST_DISPLAY_GRAPHS_ON_FAILURE_COMMAND");
else if (result == TestResult::Success)
// ISOLTEST_DISPLAY_GRAPHS_ON_FAILURE_COMMAND will run on all succeeding tests (intended for use during reviews).
graphDisplayer = getenv("ISOLTEST_DISPLAY_GRAPHS_ON_SUCCESS_COMMAND");
if (graphDisplayer)
{
if (result == TestResult::Success)
std::cout << std::endl << m_source << std::endl;
boost::process::opstream pipe;
boost::process::child child(graphDisplayer, boost::process::std_in < pipe);
pipe << output.str();
pipe.flush();
pipe.pipe().close();
if (result == TestResult::Success)
child.wait();
else
child.detach();
}
#endif
return result;
}
+43
View File
@@ -0,0 +1,43 @@
/*
This file is part of solidity.
solidity is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
solidity is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
// SPDX-License-Identifier: GPL-3.0
#pragma once
#include <test/TestCase.h>
namespace solidity::yul
{
struct Dialect;
namespace test
{
class ControlFlowGraphTest: public solidity::frontend::test::TestCase
{
public:
static std::unique_ptr<TestCase> create(Config const& _config)
{
return std::make_unique<ControlFlowGraphTest>(_config.filename);
}
explicit ControlFlowGraphTest(std::string const& _filename);
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override;
private:
Dialect const* m_dialect = nullptr;
};
}
}
@@ -0,0 +1,65 @@
{
a()
c()
function a() {
let x := 42
sstore(x,x)
b()
function b() {}
}
function c() {
let x := 21
mstore(x,x)
b()
function b() {}
}
}
// ----
// digraph CFG {
// nodesep=0.7;
// node[shape=box];
//
// Entry [label="Entry"];
// Entry -> Block0;
// Block0 [label="\
// a: [ RET[a] ] => [ ]\l\
// c: [ RET[c] ] => [ ]\l\
// "];
// Block0Exit [label="MainExit"];
// Block0 -> Block0Exit;
//
// FunctionEntry_a_1 [label="function a()"];
// FunctionEntry_a_1 -> Block1;
// Block1 [label="\
// Assignment(x): [ 0x2a ] => [ x ]\l\
// sstore: [ x x ] => [ ]\l\
// b: [ RET[b] ] => [ ]\l\
// "];
// Block1Exit [label="FunctionReturn[a]"];
// Block1 -> Block1Exit;
//
// FunctionEntry_b_2 [label="function b()"];
// FunctionEntry_b_2 -> Block2;
// Block2 [label="\
// "];
// Block2Exit [label="FunctionReturn[b]"];
// Block2 -> Block2Exit;
//
// FunctionEntry_c_3 [label="function c()"];
// FunctionEntry_c_3 -> Block3;
// Block3 [label="\
// Assignment(x): [ 0x15 ] => [ x ]\l\
// mstore: [ x x ] => [ ]\l\
// b: [ RET[b] ] => [ ]\l\
// "];
// Block3Exit [label="FunctionReturn[c]"];
// Block3 -> Block3Exit;
//
// FunctionEntry_b_4 [label="function b()"];
// FunctionEntry_b_4 -> Block4;
// Block4 [label="\
// "];
// Block4Exit [label="FunctionReturn[b]"];
// Block4 -> Block4Exit;
//
// }
+87
View File
@@ -0,0 +1,87 @@
{
sstore(0x01, 0x0101)
for { sstore(0x02, 0x0202) } sload(0x03) { sstore(0x04, 0x0404) } {
sstore(0x05, 0x0505)
if sload(0x06) { sstore(0x07,0x0707) break }
sstore(0x08, 0x0808)
if sload(0x09) { sstore(0x0A,0x0A0A) continue }
sstore(0x0B, 0x0B0B)
}
sstore(0x0C, 0x0C0C)
}
// ----
// digraph CFG {
// nodesep=0.7;
// node[shape=box];
//
// Entry [label="Entry"];
// Entry -> Block0;
// Block0 [label="\
// sstore: [ 0x0101 0x01 ] => [ ]\l\
// sstore: [ 0x0202 0x02 ] => [ ]\l\
// "];
// Block0 -> Block0Exit [arrowhead=none];
// Block0Exit [label="Jump" shape=oval];
// Block0Exit -> Block1;
//
// Block1 [label="\
// sload: [ 0x03 ] => [ TMP[sload, 0] ]\l\
// "];
// Block1 -> Block1Exit;
// Block1Exit [label="{ TMP[sload, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block1Exit:0 -> Block2;
// Block1Exit:1 -> Block3;
//
// Block2 [label="\
// sstore: [ 0x0c0c 0x0c ] => [ ]\l\
// "];
// Block2Exit [label="MainExit"];
// Block2 -> Block2Exit;
//
// Block3 [label="\
// sstore: [ 0x0505 0x05 ] => [ ]\l\
// sload: [ 0x06 ] => [ TMP[sload, 0] ]\l\
// "];
// Block3 -> Block3Exit;
// Block3Exit [label="{ TMP[sload, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block3Exit:0 -> Block4;
// Block3Exit:1 -> Block5;
//
// Block4 [label="\
// sstore: [ 0x0808 0x08 ] => [ ]\l\
// sload: [ 0x09 ] => [ TMP[sload, 0] ]\l\
// "];
// Block4 -> Block4Exit;
// Block4Exit [label="{ TMP[sload, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block4Exit:0 -> Block6;
// Block4Exit:1 -> Block7;
//
// Block5 [label="\
// sstore: [ 0x0707 0x07 ] => [ ]\l\
// "];
// Block5 -> Block5Exit [arrowhead=none];
// Block5Exit [label="Jump" shape=oval];
// Block5Exit -> Block2;
//
// Block6 [label="\
// sstore: [ 0x0b0b 0x0b ] => [ ]\l\
// "];
// Block6 -> Block6Exit [arrowhead=none];
// Block6Exit [label="Jump" shape=oval];
// Block6Exit -> Block8;
//
// Block7 [label="\
// sstore: [ 0x0a0a 0x0a ] => [ ]\l\
// "];
// Block7 -> Block7Exit [arrowhead=none];
// Block7Exit [label="Jump" shape=oval];
// Block7Exit -> Block8;
//
// Block8 [label="\
// sstore: [ 0x0404 0x04 ] => [ ]\l\
// "];
// Block8 -> Block8Exit [arrowhead=none];
// Block8Exit [label="BackwardsJump" shape=oval];
// Block8Exit -> Block1;
//
// }
+195
View File
@@ -0,0 +1,195 @@
{
function f(a, b) -> c {
for { let x := 42 } lt(x, a) {
x := add(x, 1)
if calldataload(x)
{
sstore(0, x)
leave
sstore(0x01, 0x0101)
}
sstore(0xFF, 0xFFFF)
}
{
switch mload(x)
case 0 {
sstore(0x02, 0x0202)
break
sstore(0x03, 0x0303)
}
case 1 {
sstore(0x04, 0x0404)
leave
sstore(0x05, 0x0505)
}
case 2 {
sstore(0x06, 0x0606)
revert(0, 0)
sstore(0x07, 0x0707)
}
case 3 {
sstore(0x08, 0x0808)
}
default {
if mload(b) {
return(0, 0)
sstore(0x09, 0x0909)
}
sstore(0x0A, 0x0A0A)
}
sstore(0x0B, 0x0B0B)
}
sstore(0x0C, 0x0C0C)
}
pop(f(1,2))
}
// ----
// digraph CFG {
// nodesep=0.7;
// node[shape=box];
//
// Entry [label="Entry"];
// Entry -> Block0;
// Block0 [label="\
// f: [ RET[f] 0x02 0x01 ] => [ TMP[f, 0] ]\l\
// pop: [ TMP[f, 0] ] => [ ]\l\
// "];
// Block0Exit [label="MainExit"];
// Block0 -> Block0Exit;
//
// FunctionEntry_f_1 [label="function f(a, b) -> c"];
// FunctionEntry_f_1 -> Block1;
// Block1 [label="\
// Assignment(x): [ 0x2a ] => [ x ]\l\
// "];
// Block1 -> Block1Exit [arrowhead=none];
// Block1Exit [label="Jump" shape=oval];
// Block1Exit -> Block2;
//
// Block2 [label="\
// lt: [ a x ] => [ TMP[lt, 0] ]\l\
// "];
// Block2 -> Block2Exit;
// Block2Exit [label="{ TMP[lt, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block2Exit:0 -> Block3;
// Block2Exit:1 -> Block4;
//
// Block3 [label="\
// sstore: [ 0x0c0c 0x0c ] => [ ]\l\
// "];
// Block3Exit [label="FunctionReturn[f]"];
// Block3 -> Block3Exit;
//
// Block4 [label="\
// mload: [ x ] => [ TMP[mload, 0] ]\l\
// Assignment(GHOST[0]): [ TMP[mload, 0] ] => [ GHOST[0] ]\l\
// eq: [ GHOST[0] 0x00 ] => [ TMP[eq, 0] ]\l\
// "];
// Block4 -> Block4Exit;
// Block4Exit [label="{ TMP[eq, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block4Exit:0 -> Block5;
// Block4Exit:1 -> Block6;
//
// Block5 [label="\
// eq: [ GHOST[0] 0x01 ] => [ TMP[eq, 0] ]\l\
// "];
// Block5 -> Block5Exit;
// Block5Exit [label="{ TMP[eq, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block5Exit:0 -> Block7;
// Block5Exit:1 -> Block8;
//
// Block6 [label="\
// sstore: [ 0x0202 0x02 ] => [ ]\l\
// "];
// Block6 -> Block6Exit [arrowhead=none];
// Block6Exit [label="Jump" shape=oval];
// Block6Exit -> Block3;
//
// Block7 [label="\
// eq: [ GHOST[0] 0x02 ] => [ TMP[eq, 0] ]\l\
// "];
// Block7 -> Block7Exit;
// Block7Exit [label="{ TMP[eq, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block7Exit:0 -> Block9;
// Block7Exit:1 -> Block10;
//
// Block8 [label="\
// sstore: [ 0x0404 0x04 ] => [ ]\l\
// "];
// Block8Exit [label="FunctionReturn[f]"];
// Block8 -> Block8Exit;
//
// Block9 [label="\
// eq: [ GHOST[0] 0x03 ] => [ TMP[eq, 0] ]\l\
// "];
// Block9 -> Block9Exit;
// Block9Exit [label="{ TMP[eq, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block9Exit:0 -> Block11;
// Block9Exit:1 -> Block12;
//
// Block10 [label="\
// sstore: [ 0x0606 0x06 ] => [ ]\l\
// revert: [ 0x00 0x00 ] => [ ]\l\
// "];
// Block10Exit [label="Terminated"];
// Block10 -> Block10Exit;
//
// Block11 [label="\
// mload: [ b ] => [ TMP[mload, 0] ]\l\
// "];
// Block11 -> Block11Exit;
// Block11Exit [label="{ TMP[mload, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block11Exit:0 -> Block13;
// Block11Exit:1 -> Block14;
//
// Block12 [label="\
// sstore: [ 0x0808 0x08 ] => [ ]\l\
// "];
// Block12 -> Block12Exit [arrowhead=none];
// Block12Exit [label="Jump" shape=oval];
// Block12Exit -> Block15;
//
// Block13 [label="\
// sstore: [ 0x0a0a 0x0a ] => [ ]\l\
// "];
// Block13 -> Block13Exit [arrowhead=none];
// Block13Exit [label="Jump" shape=oval];
// Block13Exit -> Block15;
//
// Block14 [label="\
// return: [ 0x00 0x00 ] => [ ]\l\
// "];
// Block14Exit [label="Terminated"];
// Block14 -> Block14Exit;
//
// Block15 [label="\
// sstore: [ 0x0b0b 0x0b ] => [ ]\l\
// "];
// Block15 -> Block15Exit [arrowhead=none];
// Block15Exit [label="Jump" shape=oval];
// Block15Exit -> Block16;
//
// Block16 [label="\
// add: [ 0x01 x ] => [ TMP[add, 0] ]\l\
// Assignment(x): [ TMP[add, 0] ] => [ x ]\l\
// calldataload: [ x ] => [ TMP[calldataload, 0] ]\l\
// "];
// Block16 -> Block16Exit;
// Block16Exit [label="{ TMP[calldataload, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block16Exit:0 -> Block17;
// Block16Exit:1 -> Block18;
//
// Block17 [label="\
// sstore: [ 0xffff 0xff ] => [ ]\l\
// "];
// Block17 -> Block17Exit [arrowhead=none];
// Block17Exit [label="BackwardsJump" shape=oval];
// Block17Exit -> Block2;
//
// Block18 [label="\
// sstore: [ x 0x00 ] => [ ]\l\
// "];
// Block18Exit [label="FunctionReturn[f]"];
// Block18 -> Block18Exit;
//
// }
+51
View File
@@ -0,0 +1,51 @@
{
sstore(0x01, 0x0101)
for { sstore(0x02, 0x0202) } sload(0x03) { sstore(0x04, 0x0404) } {
sstore(0x05, 0x0505)
}
sstore(0x06, 0x0506)
}
// ----
// digraph CFG {
// nodesep=0.7;
// node[shape=box];
//
// Entry [label="Entry"];
// Entry -> Block0;
// Block0 [label="\
// sstore: [ 0x0101 0x01 ] => [ ]\l\
// sstore: [ 0x0202 0x02 ] => [ ]\l\
// "];
// Block0 -> Block0Exit [arrowhead=none];
// Block0Exit [label="Jump" shape=oval];
// Block0Exit -> Block1;
//
// Block1 [label="\
// sload: [ 0x03 ] => [ TMP[sload, 0] ]\l\
// "];
// Block1 -> Block1Exit;
// Block1Exit [label="{ TMP[sload, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block1Exit:0 -> Block2;
// Block1Exit:1 -> Block3;
//
// Block2 [label="\
// sstore: [ 0x0506 0x06 ] => [ ]\l\
// "];
// Block2Exit [label="MainExit"];
// Block2 -> Block2Exit;
//
// Block3 [label="\
// sstore: [ 0x0505 0x05 ] => [ ]\l\
// "];
// Block3 -> Block3Exit [arrowhead=none];
// Block3Exit [label="Jump" shape=oval];
// Block3Exit -> Block4;
//
// Block4 [label="\
// sstore: [ 0x0404 0x04 ] => [ ]\l\
// "];
// Block4 -> Block4Exit [arrowhead=none];
// Block4Exit [label="BackwardsJump" shape=oval];
// Block4Exit -> Block1;
//
// }
@@ -0,0 +1,75 @@
{
function f(a, b) -> r {
let x := add(a,b)
r := sub(x,a)
}
function g() {
sstore(0x01, 0x0101)
}
function h(x) {
h(f(x, 0))
g()
}
function i() -> v, w {
v := 0x0202
w := 0x0303
}
let x, y := i()
h(x)
h(y)
}
// ----
// digraph CFG {
// nodesep=0.7;
// node[shape=box];
//
// Entry [label="Entry"];
// Entry -> Block0;
// Block0 [label="\
// i: [ RET[i] ] => [ TMP[i, 0] TMP[i, 1] ]\l\
// Assignment(x, y): [ TMP[i, 0] TMP[i, 1] ] => [ x y ]\l\
// h: [ RET[h] x ] => [ ]\l\
// h: [ RET[h] y ] => [ ]\l\
// "];
// Block0Exit [label="MainExit"];
// Block0 -> Block0Exit;
//
// FunctionEntry_f_1 [label="function f(a, b) -> r"];
// FunctionEntry_f_1 -> Block1;
// Block1 [label="\
// add: [ b a ] => [ TMP[add, 0] ]\l\
// Assignment(x): [ TMP[add, 0] ] => [ x ]\l\
// sub: [ a x ] => [ TMP[sub, 0] ]\l\
// Assignment(r): [ TMP[sub, 0] ] => [ r ]\l\
// "];
// Block1Exit [label="FunctionReturn[f]"];
// Block1 -> Block1Exit;
//
// FunctionEntry_g_2 [label="function g()"];
// FunctionEntry_g_2 -> Block2;
// Block2 [label="\
// sstore: [ 0x0101 0x01 ] => [ ]\l\
// "];
// Block2Exit [label="FunctionReturn[g]"];
// Block2 -> Block2Exit;
//
// FunctionEntry_h_3 [label="function h(x)"];
// FunctionEntry_h_3 -> Block3;
// Block3 [label="\
// f: [ RET[f] 0x00 x ] => [ TMP[f, 0] ]\l\
// h: [ RET[h] TMP[f, 0] ] => [ ]\l\
// g: [ RET[g] ] => [ ]\l\
// "];
// Block3Exit [label="FunctionReturn[h]"];
// Block3 -> Block3Exit;
//
// FunctionEntry_i_4 [label="function i() -> v, w"];
// FunctionEntry_i_4 -> Block4;
// Block4 [label="\
// Assignment(v): [ 0x0202 ] => [ v ]\l\
// Assignment(w): [ 0x0303 ] => [ w ]\l\
// "];
// Block4Exit [label="FunctionReturn[i]"];
// Block4 -> Block4Exit;
//
// }
+37
View File
@@ -0,0 +1,37 @@
{
sstore(0x01, 0x0101)
if calldataload(0) {
sstore(0x02, 0x0202)
}
sstore(0x03, 0x003)
}
// ----
// digraph CFG {
// nodesep=0.7;
// node[shape=box];
//
// Entry [label="Entry"];
// Entry -> Block0;
// Block0 [label="\
// sstore: [ 0x0101 0x01 ] => [ ]\l\
// calldataload: [ 0x00 ] => [ TMP[calldataload, 0] ]\l\
// "];
// Block0 -> Block0Exit;
// Block0Exit [label="{ TMP[calldataload, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block0Exit:0 -> Block1;
// Block0Exit:1 -> Block2;
//
// Block1 [label="\
// sstore: [ 0x03 0x03 ] => [ ]\l\
// "];
// Block1Exit [label="MainExit"];
// Block1 -> Block1Exit;
//
// Block2 [label="\
// sstore: [ 0x0202 0x02 ] => [ ]\l\
// "];
// Block2 -> Block2Exit [arrowhead=none];
// Block2Exit [label="Jump" shape=oval];
// Block2Exit -> Block1;
//
// }
+51
View File
@@ -0,0 +1,51 @@
{
function f(a, b) -> c {
sstore(0x01, 0x0101)
if lt(a,b) {
sstore(0x02, 0x0202)
leave
sstore(0x03, 0x0303)
}
sstore(0x04, 0x0404)
}
pop(f(0,1))
}
// ----
// digraph CFG {
// nodesep=0.7;
// node[shape=box];
//
// Entry [label="Entry"];
// Entry -> Block0;
// Block0 [label="\
// f: [ RET[f] 0x01 0x00 ] => [ TMP[f, 0] ]\l\
// pop: [ TMP[f, 0] ] => [ ]\l\
// "];
// Block0Exit [label="MainExit"];
// Block0 -> Block0Exit;
//
// FunctionEntry_f_1 [label="function f(a, b) -> c"];
// FunctionEntry_f_1 -> Block1;
// Block1 [label="\
// sstore: [ 0x0101 0x01 ] => [ ]\l\
// lt: [ b a ] => [ TMP[lt, 0] ]\l\
// "];
// Block1 -> Block1Exit;
// Block1Exit [label="{ TMP[lt, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block1Exit:0 -> Block2;
// Block1Exit:1 -> Block3;
//
// Block2 [label="\
// sstore: [ 0x0404 0x04 ] => [ ]\l\
// "];
// Block2Exit [label="FunctionReturn[f]"];
// Block2 -> Block2Exit;
//
// Block3 [label="\
// sstore: [ 0x0202 0x02 ] => [ ]\l\
// "];
// Block3Exit [label="FunctionReturn[f]"];
// Block3 -> Block3Exit;
//
// }
@@ -0,0 +1,193 @@
{
for { let x := 0 } lt(x, 0x0101) {
sstore(x, 0x0202)
for { let y := 0 } lt(y, 0x0303) { y := add(y, 0x0404) } {
sstore(y, 0x0505)
}
x := add(x, 0x0202)
}
{
sstore(0x0606, 0x0606)
if sload(0x0707) { continue }
sstore(0x0808, 0x0808)
if sload(0x0909) { break }
sstore(0x0A0A, 0x0B0B)
for { let z := 0 } lt(z, 0x0C0C) { z := add(z, 1) } {
sstore(0x0D0D, 0x0D0D)
if sload(0x0E0E) {
continue
}
sstore(0x0F0F, 0x0F0F)
if sload(0x1010) {
break
}
sstore(0x1111, 0x1111)
}
sstore(0x1212, 0x1212)
}
}
// ----
// digraph CFG {
// nodesep=0.7;
// node[shape=box];
//
// Entry [label="Entry"];
// Entry -> Block0;
// Block0 [label="\
// Assignment(x): [ 0x00 ] => [ x ]\l\
// "];
// Block0 -> Block0Exit [arrowhead=none];
// Block0Exit [label="Jump" shape=oval];
// Block0Exit -> Block1;
//
// Block1 [label="\
// lt: [ 0x0101 x ] => [ TMP[lt, 0] ]\l\
// "];
// Block1 -> Block1Exit;
// Block1Exit [label="{ TMP[lt, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block1Exit:0 -> Block2;
// Block1Exit:1 -> Block3;
//
// Block2 [label="\
// "];
// Block2Exit [label="MainExit"];
// Block2 -> Block2Exit;
//
// Block3 [label="\
// sstore: [ 0x0606 0x0606 ] => [ ]\l\
// sload: [ 0x0707 ] => [ TMP[sload, 0] ]\l\
// "];
// Block3 -> Block3Exit;
// Block3Exit [label="{ TMP[sload, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block3Exit:0 -> Block4;
// Block3Exit:1 -> Block5;
//
// Block4 [label="\
// sstore: [ 0x0808 0x0808 ] => [ ]\l\
// sload: [ 0x0909 ] => [ TMP[sload, 0] ]\l\
// "];
// Block4 -> Block4Exit;
// Block4Exit [label="{ TMP[sload, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block4Exit:0 -> Block6;
// Block4Exit:1 -> Block7;
//
// Block5 [label="\
// "];
// Block5 -> Block5Exit [arrowhead=none];
// Block5Exit [label="Jump" shape=oval];
// Block5Exit -> Block8;
//
// Block6 [label="\
// sstore: [ 0x0b0b 0x0a0a ] => [ ]\l\
// Assignment(z): [ 0x00 ] => [ z ]\l\
// "];
// Block6 -> Block6Exit [arrowhead=none];
// Block6Exit [label="Jump" shape=oval];
// Block6Exit -> Block9;
//
// Block7 [label="\
// "];
// Block7 -> Block7Exit [arrowhead=none];
// Block7Exit [label="Jump" shape=oval];
// Block7Exit -> Block2;
//
// Block8 [label="\
// sstore: [ 0x0202 x ] => [ ]\l\
// Assignment(y): [ 0x00 ] => [ y ]\l\
// "];
// Block8 -> Block8Exit [arrowhead=none];
// Block8Exit [label="Jump" shape=oval];
// Block8Exit -> Block10;
//
// Block9 [label="\
// lt: [ 0x0c0c z ] => [ TMP[lt, 0] ]\l\
// "];
// Block9 -> Block9Exit;
// Block9Exit [label="{ TMP[lt, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block9Exit:0 -> Block11;
// Block9Exit:1 -> Block12;
//
// Block10 [label="\
// lt: [ 0x0303 y ] => [ TMP[lt, 0] ]\l\
// "];
// Block10 -> Block10Exit;
// Block10Exit [label="{ TMP[lt, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block10Exit:0 -> Block13;
// Block10Exit:1 -> Block14;
//
// Block11 [label="\
// sstore: [ 0x1212 0x1212 ] => [ ]\l\
// "];
// Block11 -> Block11Exit [arrowhead=none];
// Block11Exit [label="Jump" shape=oval];
// Block11Exit -> Block8;
//
// Block12 [label="\
// sstore: [ 0x0d0d 0x0d0d ] => [ ]\l\
// sload: [ 0x0e0e ] => [ TMP[sload, 0] ]\l\
// "];
// Block12 -> Block12Exit;
// Block12Exit [label="{ TMP[sload, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block12Exit:0 -> Block15;
// Block12Exit:1 -> Block16;
//
// Block13 [label="\
// add: [ 0x0202 x ] => [ TMP[add, 0] ]\l\
// Assignment(x): [ TMP[add, 0] ] => [ x ]\l\
// "];
// Block13 -> Block13Exit [arrowhead=none];
// Block13Exit [label="BackwardsJump" shape=oval];
// Block13Exit -> Block1;
//
// Block14 [label="\
// sstore: [ 0x0505 y ] => [ ]\l\
// "];
// Block14 -> Block14Exit [arrowhead=none];
// Block14Exit [label="Jump" shape=oval];
// Block14Exit -> Block17;
//
// Block15 [label="\
// sstore: [ 0x0f0f 0x0f0f ] => [ ]\l\
// sload: [ 0x1010 ] => [ TMP[sload, 0] ]\l\
// "];
// Block15 -> Block15Exit;
// Block15Exit [label="{ TMP[sload, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block15Exit:0 -> Block18;
// Block15Exit:1 -> Block19;
//
// Block16 [label="\
// "];
// Block16 -> Block16Exit [arrowhead=none];
// Block16Exit [label="Jump" shape=oval];
// Block16Exit -> Block20;
//
// Block17 [label="\
// add: [ 0x0404 y ] => [ TMP[add, 0] ]\l\
// Assignment(y): [ TMP[add, 0] ] => [ y ]\l\
// "];
// Block17 -> Block17Exit [arrowhead=none];
// Block17Exit [label="BackwardsJump" shape=oval];
// Block17Exit -> Block10;
//
// Block18 [label="\
// sstore: [ 0x1111 0x1111 ] => [ ]\l\
// "];
// Block18 -> Block18Exit [arrowhead=none];
// Block18Exit [label="Jump" shape=oval];
// Block18Exit -> Block20;
//
// Block19 [label="\
// "];
// Block19 -> Block19Exit [arrowhead=none];
// Block19Exit [label="Jump" shape=oval];
// Block19Exit -> Block11;
//
// Block20 [label="\
// add: [ 0x01 z ] => [ TMP[add, 0] ]\l\
// Assignment(z): [ TMP[add, 0] ] => [ z ]\l\
// "];
// Block20 -> Block20Exit [arrowhead=none];
// Block20Exit [label="BackwardsJump" shape=oval];
// Block20Exit -> Block9;
//
// }
+15
View File
@@ -0,0 +1,15 @@
{
}
// ----
// digraph CFG {
// nodesep=0.7;
// node[shape=box];
//
// Entry [label="Entry"];
// Entry -> Block0;
// Block0 [label="\
// "];
// Block0Exit [label="MainExit"];
// Block0 -> Block0Exit;
//
// }
@@ -0,0 +1,68 @@
{
sstore(0, 0)
switch sload(0)
case 0 {
sstore(0x01, 0x0101)
}
case 1 {
sstore(0x02, 0x0101)
}
default {
sstore(0x03, 0x0101)
}
sstore(0x04, 0x0101)
}
// ----
// digraph CFG {
// nodesep=0.7;
// node[shape=box];
//
// Entry [label="Entry"];
// Entry -> Block0;
// Block0 [label="\
// sstore: [ 0x00 0x00 ] => [ ]\l\
// sload: [ 0x00 ] => [ TMP[sload, 0] ]\l\
// Assignment(GHOST[0]): [ TMP[sload, 0] ] => [ GHOST[0] ]\l\
// eq: [ GHOST[0] 0x00 ] => [ TMP[eq, 0] ]\l\
// "];
// Block0 -> Block0Exit;
// Block0Exit [label="{ TMP[eq, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block0Exit:0 -> Block1;
// Block0Exit:1 -> Block2;
//
// Block1 [label="\
// eq: [ GHOST[0] 0x01 ] => [ TMP[eq, 0] ]\l\
// "];
// Block1 -> Block1Exit;
// Block1Exit [label="{ TMP[eq, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord];
// Block1Exit:0 -> Block3;
// Block1Exit:1 -> Block4;
//
// Block2 [label="\
// sstore: [ 0x0101 0x01 ] => [ ]\l\
// "];
// Block2 -> Block2Exit [arrowhead=none];
// Block2Exit [label="Jump" shape=oval];
// Block2Exit -> Block5;
//
// Block3 [label="\
// sstore: [ 0x0101 0x03 ] => [ ]\l\
// "];
// Block3 -> Block3Exit [arrowhead=none];
// Block3Exit [label="Jump" shape=oval];
// Block3Exit -> Block5;
//
// Block4 [label="\
// sstore: [ 0x0101 0x02 ] => [ ]\l\
// "];
// Block4 -> Block4Exit [arrowhead=none];
// Block4Exit [label="Jump" shape=oval];
// Block4Exit -> Block5;
//
// Block5 [label="\
// sstore: [ 0x0101 0x04 ] => [ ]\l\
// "];
// Block5Exit [label="MainExit"];
// Block5 -> Block5Exit;
//
// }
@@ -0,0 +1,31 @@
{
let x := calldataload(0)
let y := calldataload(2)
x := calldataload(3)
y := calldataload(4)
sstore(x,y)
}
// ----
// digraph CFG {
// nodesep=0.7;
// node[shape=box];
//
// Entry [label="Entry"];
// Entry -> Block0;
// Block0 [label="\
// calldataload: [ 0x00 ] => [ TMP[calldataload, 0] ]\l\
// Assignment(x): [ TMP[calldataload, 0] ] => [ x ]\l\
// calldataload: [ 0x02 ] => [ TMP[calldataload, 0] ]\l\
// Assignment(y): [ TMP[calldataload, 0] ] => [ y ]\l\
// calldataload: [ 0x03 ] => [ TMP[calldataload, 0] ]\l\
// Assignment(x): [ TMP[calldataload, 0] ] => [ x ]\l\
// calldataload: [ 0x04 ] => [ TMP[calldataload, 0] ]\l\
// Assignment(y): [ TMP[calldataload, 0] ] => [ y ]\l\
// sstore: [ y x ] => [ ]\l\
// "];
// Block0Exit [label="MainExit"];
// Block0 -> Block0Exit;
//
// }
@@ -0,0 +1,26 @@
{
let a_1 := 42
let a_2 := 23
let a_3 := 1
let b := verbatim_10i_1o("test", a_1, a_2, a_3, 2, 3, 4, 5, 6, 7, 8)
sstore(b,b)
}
// ----
// digraph CFG {
// nodesep=0.7;
// node[shape=box];
//
// Entry [label="Entry"];
// Entry -> Block0;
// Block0 [label="\
// Assignment(a_1): [ 0x2a ] => [ a_1 ]\l\
// Assignment(a_2): [ 0x17 ] => [ a_2 ]\l\
// Assignment(a_3): [ 0x01 ] => [ a_3 ]\l\
// verbatim_10i_1o: [ 0x08 0x07 0x06 0x05 0x04 0x03 0x02 a_3 a_2 a_1 ] => [ TMP[verbatim_10i_1o, 0] ]\l\
// Assignment(b): [ TMP[verbatim_10i_1o, 0] ] => [ b ]\l\
// sstore: [ b b ] => [ ]\l\
// "];
// Block0Exit [label="MainExit"];
// Block0 -> Block0Exit;
//
// }
+3 -1
View File
@@ -32,6 +32,7 @@ add_executable(isoltest
../libsolidity/ASTJSONTest.cpp
../libsolidity/SMTCheckerTest.cpp
../libyul/Common.cpp
../libyul/ControlFlowGraphTest.cpp
../libyul/EVMCodeTransformTest.cpp
../libyul/EwasmTranslationTest.cpp
../libyul/FunctionSideEffects.cpp
@@ -41,4 +42,5 @@ add_executable(isoltest
../libyul/YulOptimizerTestCommon.cpp
../libyul/YulInterpreterTest.cpp
)
target_link_libraries(isoltest PRIVATE evmc libsolc solidity yulInterpreter evmasm Boost::boost Boost::program_options Boost::unit_test_framework)
target_compile_definitions(isoltest PRIVATE ISOLTEST)
target_link_libraries(isoltest PRIVATE evmc libsolc solidity yulInterpreter evmasm Boost::boost Boost::program_options Boost::unit_test_framework Threads::Threads)