Skip to content

Commit

Permalink
Add Yul CFG export tests
Browse files Browse the repository at this point in the history
  • Loading branch information
r0qs committed Oct 14, 2024
1 parent 7e9efe0 commit a4f1d9d
Show file tree
Hide file tree
Showing 9 changed files with 9,546 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/cmdlineTests/standard_yul_cfg_json_export/in.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;

interface I {
function f() external pure returns (uint);
}

contract C is I {
function f() public pure override returns (uint) {
return 42;
}
}

contract D {
function f() public returns (uint) {
C c = new C();
return c.f();
}
}
13 changes: 13 additions & 0 deletions test/cmdlineTests/standard_yul_cfg_json_export/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"language": "Solidity",
"sources": {
"C": {"urls": ["standard_yul_cfg_json_export/in.sol"]}
},
"settings": {
"optimizer": {
"enabled": true
},
"viaIR": true,
"outputSelection": {"*": {"*": ["yulCFGJson"]}}
}
}
3,969 changes: 3,969 additions & 0 deletions test/cmdlineTests/standard_yul_cfg_json_export/output.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/cmdlineTests/strict_asm_yul_cfg_json_export/args
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--strict-assembly --optimize --yul-cfg-json --pretty-json --json-indent 4
128 changes: 128 additions & 0 deletions test/cmdlineTests/strict_asm_yul_cfg_json_export/input.yul
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/// @use-src 0:"input.sol"
object "D_38" {
code {
{
/// @src 0:225:331 "contract D {..."
let _1 := memoryguard(0x80)
mstore(64, _1)
if callvalue() { revert(0, 0) }
let _2 := datasize("D_38_deployed")
codecopy(_1, dataoffset("D_38_deployed"), _2)
return(_1, _2)
}
}
/// @use-src 0:"input.sol"
object "D_38_deployed" {
code {
{
/// @src 0:225:331 "contract D {..."
let _1 := memoryguard(0x80)
mstore(64, _1)
if iszero(lt(calldatasize(), 4))
{
if eq(0x26121ff0, shr(224, calldataload(0)))
{
if callvalue() { revert(0, 0) }
if slt(add(calldatasize(), not(3)), 0) { revert(0, 0) }
/// @src 0:293:300 "new C()"
let _2 := datasize("C_19")
let _3 := add(_1, _2)
if or(gt(_3, 0xffffffffffffffff), lt(_3, _1))
{
/// @src 0:225:331 "contract D {..."
mstore(0, shl(224, 0x4e487b71))
mstore(4, 0x41)
revert(0, 0x24)
}
/// @src 0:293:300 "new C()"
datacopy(_1, dataoffset("C_19"), _2)
let expr_address := create(/** @src 0:225:331 "contract D {..." */ 0, /** @src 0:293:300 "new C()" */ _1, sub(_3, _1))
if iszero(expr_address)
{
/// @src 0:225:331 "contract D {..."
let pos := mload(64)
returndatacopy(pos, 0, returndatasize())
revert(pos, returndatasize())
}
/// @src 0:317:322 "c.f()"
let _4 := /** @src 0:225:331 "contract D {..." */ mload(64)
/// @src 0:317:322 "c.f()"
mstore(_4, /** @src 0:225:331 "contract D {..." */ shl(228, 0x026121ff))
/// @src 0:317:322 "c.f()"
let _5 := staticcall(gas(), /** @src 0:225:331 "contract D {..." */ and(/** @src 0:317:320 "c.f" */ expr_address, /** @src 0:225:331 "contract D {..." */ sub(shl(160, /** @src 0:293:300 "new C()" */ 1), 1)), /** @src 0:317:322 "c.f()" */ _4, /** @src 0:225:331 "contract D {..." */ 4, /** @src 0:317:322 "c.f()" */ _4, 32)
if iszero(_5)
{
/// @src 0:225:331 "contract D {..."
let pos_1 := mload(64)
returndatacopy(pos_1, 0, returndatasize())
revert(pos_1, returndatasize())
}
/// @src 0:317:322 "c.f()"
let expr := /** @src 0:225:331 "contract D {..." */ 0
/// @src 0:317:322 "c.f()"
if _5
{
let _6 := 32
if gt(32, returndatasize()) { _6 := returndatasize() }
/// @src 0:225:331 "contract D {..."
let newFreePtr := add(_4, and(add(_6, 31), not(31)))
if or(gt(newFreePtr, /** @src 0:293:300 "new C()" */ 0xffffffffffffffff), /** @src 0:225:331 "contract D {..." */ lt(newFreePtr, _4))
{
mstore(0, shl(224, 0x4e487b71))
mstore(4, 0x41)
revert(0, 0x24)
}
mstore(64, newFreePtr)
if slt(sub(/** @src 0:317:322 "c.f()" */ add(_4, _6), /** @src 0:225:331 "contract D {..." */ _4), /** @src 0:317:322 "c.f()" */ 32)
/// @src 0:225:331 "contract D {..."
{ revert(0, 0) }
/// @src 0:317:322 "c.f()"
expr := /** @src 0:225:331 "contract D {..." */ mload(_4)
}
let memPos := mload(64)
mstore(memPos, expr)
return(memPos, /** @src 0:317:322 "c.f()" */ 32)
}
}
/// @src 0:225:331 "contract D {..."
revert(0, 0)
}
}
/// @use-src 0:"input.sol"
object "C_19" {
code {
{
/// @src 0:124:223 "contract C is I {..."
let _1 := memoryguard(0x80)
mstore(64, _1)
if callvalue() { revert(0, 0) }
let _2 := datasize("C_19_deployed")
codecopy(_1, dataoffset("C_19_deployed"), _2)
return(_1, _2)
}
}
/// @use-src 0:"input.sol"
object "C_19_deployed" {
code {
{
/// @src 0:124:223 "contract C is I {..."
let _1 := memoryguard(0x80)
mstore(64, _1)
if iszero(lt(calldatasize(), 4))
{
if eq(0x26121ff0, shr(224, calldataload(0)))
{
if callvalue() { revert(0, 0) }
if slt(add(calldatasize(), not(3)), 0) { revert(0, 0) }
mstore(_1, /** @src 0:212:214 "42" */ 0x2a)
/// @src 0:124:223 "contract C is I {..."
return(_1, 32)
}
}
revert(0, 0)
}
}
}
}
}
}
Loading

0 comments on commit a4f1d9d

Please sign in to comment.