Added sameType check for fromType and toType in YulUtilFunctions.cpp and relevant tests in semanticTests

This commit is contained in:
nishant-sachdeva 2021-12-06 18:01:27 +05:30
parent e49780362b
commit 7cc7a0f183
2 changed files with 58 additions and 36 deletions

View File

@ -4,12 +4,27 @@ contract C {
function testFunction3() public {}
function() external [3] externalArray0;
function() external [3] externalArray1 = [
this.testFunction1,
this.testFunction2,
this.testFunction3
];
function() external [] externalArray0;
function() external [] externalArray1;
function() internal [] internalArray0;
function() internal [] internalArray1;
constructor() {
externalArray0 = new function() external[] (3);
externalArray1 = [
this.testFunction1,
this.testFunction2,
this.testFunction3
];
internalArray0 = new function() internal[] (3);
internalArray1 = [
testFunction1,
testFunction2,
testFunction3
];
}
function copyExternalStorageArrayOfFunctionType() external returns (bool) {
assert(keccak256(abi.encode(externalArray0)) != keccak256(abi.encode(externalArray1)));
@ -17,27 +32,22 @@ contract C {
return keccak256(abi.encode(externalArray0)) == keccak256(abi.encode(externalArray1));
}
function() internal [3] internalArray0;
function() internal [3] internalArray1 = [
testFunction1,
testFunction2,
testFunction3
];
function copyInternalArrayOfFunctionType() external returns (bool) {
internalArray0 = internalArray1;
assert(internalArray0.length == 3);
return
internalArray0.length == internalArray1.length &&
internalArray0[0] == internalArray1[0] &&
internalArray0[1] == internalArray1[1] &&
internalArray0[2] == internalArray1[2];
internalArray0.length == internalArray1.length &&
internalArray0[0] == internalArray1[0] &&
internalArray0[1] == internalArray1[1] &&
internalArray0[2] == internalArray1[2];
}
}
// ====
// compileViaYul: also
// ----
// copyExternalStorageArrayOfFunctionType() -> true
// gas legacy: 103412
// gas irOptimized: 104701
// gas legacy: 108725
// gas legacyOptimized: 102441
// copyInternalArrayOfFunctionType() -> true

View File

@ -3,12 +3,29 @@ contract C {
function testFunction2() public view {}
function testFunction3() public pure {}
function() external [3] externalArray0;
function() external [3] externalArray1 = [
this.testFunction1,
this.testFunction2,
this.testFunction3
];
function() external [] externalArray0;
function() external [] externalArray1;
function() internal [] internalArray0;
function() internal [] internalArray1;
constructor() {
externalArray0 = new function() external[] (3);
externalArray1 = [
this.testFunction1,
this.testFunction2,
this.testFunction3
];
internalArray0 = new function() internal[] (3);
internalArray1 = [
testFunction1,
testFunction2,
testFunction3
];
}
function copyExternalStorageArraysOfFunctionType() external returns (bool)
{
@ -17,29 +34,24 @@ contract C {
return keccak256(abi.encodePacked(externalArray0)) == keccak256(abi.encodePacked(externalArray1));
}
function() internal [3] internalArray0;
function() internal [3] internalArray1 = [
testFunction1,
testFunction2,
testFunction3
];
function copyInternalArrayOfFunctionType() external returns (bool)
{
internalArray0 = internalArray1;
assert(internalArray0.length == 3);
return
internalArray0.length == internalArray1.length &&
internalArray0[0] == internalArray1[0] &&
internalArray0[1] == internalArray1[1] &&
internalArray0[2] == internalArray1[2];
internalArray0.length == internalArray1.length &&
internalArray0[0] == internalArray1[0] &&
internalArray0[1] == internalArray1[1] &&
internalArray0[2] == internalArray1[2];
}
}
// ====
// compileViaYul: also
// ----
// copyExternalStorageArraysOfFunctionType() -> true
// gas legacy: 103398
// gas irOptimized: 104372
// gas legacy: 108462
// gas legacyOptimized: 102174
// copyInternalArrayOfFunctionType() -> true
// gas legacy: 104178