Merge pull request #12123 from ethereum/empty-switch-12068

CodeGen: Only output switch when it has cases
This commit is contained in:
chriseth 2021-10-12 17:42:49 +02:00 committed by GitHub
commit 49d7b78466
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 40 additions and 78 deletions

View File

@ -17,6 +17,7 @@ Bugfixes:
* Commandline Interface: Report output selection options unsupported by the selected input mode instead of ignoring them.
* SMTChecker: Fix internal error in magic type access (``block``, ``msg``, ``tx``).
* TypeChecker: Fix internal error when using user defined value types in public library functions.
* Yul IR Generator: Do not output empty switches/if-bodies for empty contracts.

View File

@ -967,7 +967,7 @@ string IRGenerator::callValueCheck()
string IRGenerator::dispatchRoutine(ContractDefinition const& _contract)
{
Whiskers t(R"X(
if iszero(lt(calldatasize(), 4))
<?+cases>if iszero(lt(calldatasize(), 4))
{
let selector := <shr224>(calldataload(0))
switch selector
@ -985,8 +985,8 @@ string IRGenerator::dispatchRoutine(ContractDefinition const& _contract)
}
</cases>
default {}
}
if iszero(calldatasize()) { <receiveEther> }
}</+cases>
<?+receiveEther>if iszero(calldatasize()) { <receiveEther> }</+receiveEther>
<fallback>
)X");
t("shr224", m_utils.shiftRightFunction(224));

View File

@ -189,11 +189,13 @@ string Whiskers::replace(
if (conditionName[0] == '+')
{
string tag = conditionName.substr(1);
assertThrow(
_parameters.count(tag),
WhiskersError, "Tag " + tag + " used as condition but was not set."
);
conditionValue = !_parameters.at(tag).empty();
if (_parameters.count(tag))
conditionValue = !_parameters.at(tag).empty();
else if (_listParameters.count(tag))
conditionValue = !_listParameters.at(tag).empty();
else
assertThrow(false, WhiskersError, "Tag " + tag + " used as condition but was not set.");
}
else
{

View File

@ -60,12 +60,13 @@ DEV_SIMPLE_EXCEPTION(WhiskersError);
* - Condition parameter: <?name>...<!name>...</name>, where "<!name>" is optional
* replaced (and recursively expanded) by the first part if the condition is true
* and by the second (or empty string if missing) if the condition is false
* - Conditional string parameter: <?+name>...<!+name>...</+name>
* Works similar to a conditional parameter where the checked condition is
* that the regular (string) parameter called "name" is non-empty.
* - List parameter: <#list>...</list>
* The part between the tags is repeated as often as values are provided
* in the mapping. Each list element can have its own parameter -> value mapping.
* - Conditional value parameter: <?+name>...<!+name>...</+name>
* Works similar to a conditional parameter where the checked condition is
* that the string or list parameter called "name" is non-empty or contains
* no elements respectively.
*/
class Whiskers
{

View File

@ -44,14 +44,6 @@ object "C_2" {
/// @src 0:265:278 "contract C {}"
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{
let selector := shift_right_224_unsigned(calldataload(0))
switch selector
default {}
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue {
@ -175,7 +167,7 @@ object "D_27" {
default {}
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue {
@ -413,14 +405,6 @@ object "D_27" {
/// @src 0:265:278 "contract C {}"
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{
let selector := shift_right_224_unsigned(calldataload(0))
switch selector
default {}
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue {
@ -499,7 +483,7 @@ object "D_27" {
revert(pos, returndatasize())
}
mstore(add(allocate_memory_array_string(), 32), "/*")
let memPtr := allocate_memory_array_string_482()
let memPtr := allocate_memory_array_string_480()
mstore(add(memPtr, 32), 0x2f2a2a204073726320303a39363a313635202022636f6e74726163742044207b)
mstore(add(memPtr, 64), shl(200, 0x2e2e2e22202a2f))
let memPos := mload(64)
@ -540,7 +524,7 @@ object "D_27" {
memPtr := memPtr_1
mstore(memPtr_1, 2)
}
function allocate_memory_array_string_482() -> memPtr
function allocate_memory_array_string_480() -> memPtr
{
let memPtr_1 := mload(64)
let newFreePtr := add(memPtr_1, 96)

View File

@ -63,7 +63,7 @@ object "C_81" {
default {}
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue {

View File

@ -49,7 +49,7 @@ object "C_59" {
for { } lt(src, srcEnd) { src := add(src, _2) }
{
if slt(sub(calldatasize(), src), _2) { revert(_1, _1) }
let value := allocate_memory_1174()
let value := allocate_memory_1172()
mstore(value, calldataload(src))
mstore(dst, value)
dst := add(dst, _2)
@ -67,7 +67,7 @@ object "C_59" {
mstore(4, 0x41)
revert(0, 0x24)
}
function allocate_memory_1174() -> memPtr
function allocate_memory_1172() -> memPtr
{
memPtr := mload(64)
let newFreePtr := add(memPtr, 32)

View File

@ -78,7 +78,7 @@ object "C_15" {
default {}
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue {

View File

@ -218,7 +218,7 @@ object \"C_54\" {
default {}
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue {
@ -639,7 +639,7 @@ object \"C_54\" {
case 0x26121ff0 {
if callvalue() { revert(_1, _1) }
abi_decode(calldatasize())
let ret := /** @src 0:286:305 \"constVar + immutVar\" */ checked_add_int256_568(/** @src 0:297:305 \"immutVar\" */ loadimmutable(\"8\"))
let ret := /** @src 0:286:305 \"constVar + immutVar\" */ checked_add_int256_566(/** @src 0:297:305 \"immutVar\" */ loadimmutable(\"8\"))
/// @src 0:79:435 \"contract C...\"
let memPos := mload(64)
return(memPos, sub(abi_encode_int256(memPos, ret), memPos))
@ -663,7 +663,7 @@ object \"C_54\" {
if callvalue() { revert(_1, _1) }
abi_decode(calldatasize())
let memPos_3 := mload(64)
return(memPos_3, sub(abi_encode_int256_567(memPos_3), memPos_3))
return(memPos_3, sub(abi_encode_int256_565(memPos_3), memPos_3))
}
}
revert(0, 0)
@ -672,7 +672,7 @@ object \"C_54\" {
{
if slt(add(dataEnd, not(3)), 0) { revert(0, 0) }
}
function abi_encode_int256_567(headStart) -> tail
function abi_encode_int256_565(headStart) -> tail
{
tail := add(headStart, 32)
mstore(headStart, /** @src 0:124:126 \"41\" */ 0x29)
@ -689,7 +689,7 @@ object \"C_54\" {
mstore(4, 0x11)
revert(0, 0x24)
}
function checked_add_int256_568(y) -> sum
function checked_add_int256_566(y) -> sum
{
if and(1, sgt(y, sub(shl(255, 1), 42))) { panic_error_0x11() }
sum := add(/** @src 0:124:126 \"41\" */ 0x29, /** @src 0:79:435 \"contract C...\" */ y)
@ -1050,7 +1050,7 @@ object \"D_72\" {
default {}
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue {
@ -1479,7 +1479,7 @@ object \"D_72\" {
case 0x26121ff0 {
if callvalue() { revert(_1, _1) }
abi_decode(calldatasize())
let ret := /** @src 0:286:305 \"constVar + immutVar\" */ checked_add_int256_568(/** @src 0:297:305 \"immutVar\" */ loadimmutable(\"8\"))
let ret := /** @src 0:286:305 \"constVar + immutVar\" */ checked_add_int256_566(/** @src 0:297:305 \"immutVar\" */ loadimmutable(\"8\"))
/// @src 1:91:166 \"contract D is C(3)...\"
let memPos := mload(64)
return(memPos, sub(abi_encode_int256(memPos, ret), memPos))
@ -1503,7 +1503,7 @@ object \"D_72\" {
if callvalue() { revert(_1, _1) }
abi_decode(calldatasize())
let memPos_3 := mload(64)
return(memPos_3, sub(abi_encode_int256_567(memPos_3), memPos_3))
return(memPos_3, sub(abi_encode_int256_565(memPos_3), memPos_3))
}
}
revert(0, 0)
@ -1512,7 +1512,7 @@ object \"D_72\" {
{
if slt(add(dataEnd, not(3)), 0) { revert(0, 0) }
}
function abi_encode_int256_567(headStart) -> tail
function abi_encode_int256_565(headStart) -> tail
{
tail := add(headStart, 32)
mstore(headStart, /** @src 0:124:126 \"41\" */ 0x29)
@ -1529,7 +1529,7 @@ object \"D_72\" {
mstore(4, 0x11)
revert(0, 0x24)
}
function checked_add_int256_568(y) -> sum
function checked_add_int256_566(y) -> sum
{
if and(1, sgt(y, sub(shl(255, 1), 42))) { panic_error_0x11() }
sum := add(/** @src 0:124:126 \"41\" */ 0x29, /** @src 1:91:166 \"contract D is C(3)...\" */ y)

View File

@ -47,7 +47,6 @@ object \"C_7\" {
}
default { }
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue
{ newValue := shr(224, value) }

View File

@ -62,7 +62,7 @@ object \"C_7\" {
default {}
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue {

View File

@ -43,14 +43,6 @@ object \"C_3\" {
/// @src 0:79:92 \"contract C {}\"
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{
let selector := shift_right_224_unsigned(calldataload(0))
switch selector
default {}
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue {
@ -139,7 +131,7 @@ object \"D_16\" {
default {}
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue {
@ -253,14 +245,6 @@ object \"D_16\" {
/// @src 0:79:92 \"contract C {}\"
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{
let selector := shift_right_224_unsigned(calldataload(0))
switch selector
default {}
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue {

View File

@ -63,7 +63,7 @@ object "test_11" {
default {}
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue {

View File

@ -31,16 +31,8 @@ object "C_7" {
{
/// @src 0:80:112 "contract C..."
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{
let selector := shift_right_unsigned(calldataload(0))
pop(selector)
}
pop(iszero(calldatasize()))
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
}
function shift_right_unsigned(value) -> newValue
{ newValue := shr(224, value) }
function revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
{ revert(0, 0) }
}

View File

@ -138,7 +138,6 @@ object "C_6" {
return(memPos, sub(memEnd, memPos))
}
}
pop(iszero(calldatasize()))
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
}
function shift_right_unsigned(value) -> newValue

View File

@ -62,7 +62,7 @@ object \"C_11\" {
default {}
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue {

View File

@ -62,7 +62,7 @@ object \"C_11\" {
default {}
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue {

View File

@ -62,7 +62,7 @@ object \"C_11\" {
default {}
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue {

View File

@ -62,7 +62,7 @@ object \"C_11\" {
default {}
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue {

View File

@ -62,7 +62,7 @@ object \"C_11\" {
default {}
}
if iszero(calldatasize()) { }
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
function shift_right_224_unsigned(value) -> newValue {