Merge pull request #10388 from ethereum/forwardRevertOnCreate

[Sol->Yul] Forward failure for creation.
This commit is contained in:
chriseth 2020-11-25 10:39:54 +01:00 committed by GitHub
commit f02bc817af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 26 additions and 5 deletions

View File

@ -1412,6 +1412,8 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
</saltSet> </saltSet>
<?isTryCall> <?isTryCall>
let <success> := iszero(iszero(<address>)) let <success> := iszero(iszero(<address>))
<!isTryCall>
if iszero(<address>) { <forwardingRevert>() }
</isTryCall> </isTryCall>
<releaseTemporaryMemory>() <releaseTemporaryMemory>()
)"); )");
@ -1434,6 +1436,8 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
t("isTryCall", _functionCall.annotation().tryCall); t("isTryCall", _functionCall.annotation().tryCall);
if (_functionCall.annotation().tryCall) if (_functionCall.annotation().tryCall)
t("success", IRNames::trySuccessConditionVariable(_functionCall)); t("success", IRNames::trySuccessConditionVariable(_functionCall));
else
t("forwardingRevert", m_utils.forwardingRevertFunction());
m_code << t.render(); m_code << t.render();
break; break;

View File

@ -59,7 +59,11 @@ object "D_13" {
let _3 := add(128, _2) let _3 := add(128, _2)
if or(gt(_3, 0xffffffffffffffff), lt(_3, 128)) { invalid() } if or(gt(_3, 0xffffffffffffffff), lt(_3, 128)) { invalid() }
datacopy(128, dataoffset("C_2"), _2) datacopy(128, dataoffset("C_2"), _2)
pop(create(_1, 128, _2)) if iszero(create(_1, 128, _2))
{
returndatacopy(_1, _1, returndatasize())
revert(_1, returndatasize())
}
return(allocateMemory(_1), _1) return(allocateMemory(_1), _1)
} }
} }

View File

@ -130,6 +130,8 @@ object \"D_13\" {
let expr_9_address := create(0, _1, sub(_2, _1)) let expr_9_address := create(0, _1, sub(_2, _1))
if iszero(expr_9_address) { revert_forward_1() }
releaseTemporaryMemory() releaseTemporaryMemory()
let vloc_c_6_address := expr_9_address let vloc_c_6_address := expr_9_address
@ -142,6 +144,11 @@ object \"D_13\" {
function releaseTemporaryMemory() { function releaseTemporaryMemory() {
} }
function revert_forward_1() {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
function shift_right_224_unsigned(value) -> newValue { function shift_right_224_unsigned(value) -> newValue {
newValue := newValue :=

View File

@ -35,7 +35,7 @@ object "C_2" {
======= viair_subobjects/input.sol:D ======= ======= viair_subobjects/input.sol:D =======
Binary: Binary:
608060405234156100105760006000fd5b60d380610020600039806000f350fe6080604052600436101515610074576000803560e01c6326121ff0141561007257341561002a578081fd5b806003193601121561003a578081fd5b6028806080016080811067ffffffffffffffff8211171561005757fe5b50806100ab60803980608083f05050806100708261007e565bf35b505b60006000fd6100a9565b6000604051905081810181811067ffffffffffffffff8211171561009e57fe5b80604052505b919050565bfe60806040523415600f5760006000fd5b600a80601e600039806000f350fe608060405260006000fd 608060405234156100105760006000fd5b60e080610020600039806000f350fe6080604052600436101515610081576000803560e01c6326121ff0141561007f57341561002a578081fd5b806003193601121561003a578081fd5b6028806080016080811067ffffffffffffffff8211171561005757fe5b50806100b860803980608083f01515610072573d82833e3d82fd5b508061007d8261008b565bf35b505b60006000fd6100b6565b6000604051905081810181811067ffffffffffffffff821117156100ab57fe5b80604052505b919050565bfe60806040523415600f5760006000fd5b600a80601e600039806000f350fe608060405260006000fd
Binary of the runtime part: Binary of the runtime part:
Optimized IR: Optimized IR:
@ -71,7 +71,11 @@ object "D_13" {
let _3 := add(128, _2) let _3 := add(128, _2)
if or(gt(_3, 0xffffffffffffffff), lt(_3, 128)) { invalid() } if or(gt(_3, 0xffffffffffffffff), lt(_3, 128)) { invalid() }
datacopy(128, dataoffset("C_2"), _2) datacopy(128, dataoffset("C_2"), _2)
pop(create(_1, 128, _2)) if iszero(create(_1, 128, _2))
{
returndatacopy(_1, _1, returndatasize())
revert(_1, returndatasize())
}
return(allocateMemory(_1), _1) return(allocateMemory(_1), _1)
} }
} }
@ -106,4 +110,3 @@ object "D_13" {
} }
} }
} }

View File

@ -16,7 +16,6 @@ contract B {
// ==== // ====
// compileViaYul: also // compileViaYul: also
// compileToEwasm: also
// ---- // ----
// testIt() -> // testIt() ->
// test() -> 2 // test() -> 2

View File

@ -19,5 +19,7 @@ contract Test {
new C(); new C();
} }
} }
// ====
// compileViaYul: also
// ---- // ----
// f() -> FAILURE // f() -> FAILURE

View File

@ -19,5 +19,7 @@ contract Test {
new C(); new C();
} }
} }
// ====
// compileViaYul: also
// ---- // ----
// f() -> FAILURE // f() -> FAILURE