mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add control flow analyzer and test for uninitialized storage returns.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f() internal returns (S storage c) {
|
||||
assembly {
|
||||
sstore(c_slot, sload(s_slot))
|
||||
}
|
||||
}
|
||||
function g(bool flag) internal returns (S storage c) {
|
||||
// control flow in assembly will not be analyzed for now,
|
||||
// so this will not issue a warning
|
||||
assembly {
|
||||
if flag {
|
||||
sstore(c_slot, sload(s_slot))
|
||||
}
|
||||
}
|
||||
}
|
||||
function h() internal returns (S storage c) {
|
||||
// any reference from assembly will be sufficient for now,
|
||||
// so this will not issue a warning
|
||||
assembly {
|
||||
sstore(s_slot, sload(c_slot))
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,10 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f() internal pure returns (S storage) {
|
||||
assembly {
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (87-88): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
@@ -0,0 +1,36 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f() internal view returns (S storage c) {
|
||||
do {} while((c = s).f);
|
||||
}
|
||||
function g() internal view returns (S storage c) {
|
||||
do { c = s; } while(false);
|
||||
}
|
||||
function h() internal view returns (S storage c) {
|
||||
c = s;
|
||||
do {} while(false);
|
||||
}
|
||||
function i() internal view returns (S storage c) {
|
||||
do {} while(false);
|
||||
c = s;
|
||||
}
|
||||
function j() internal view returns (S storage c) {
|
||||
do {
|
||||
c = s;
|
||||
break;
|
||||
} while(false);
|
||||
}
|
||||
function k() internal view returns (S storage c) {
|
||||
do {
|
||||
if (s.f) {
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
c = s;
|
||||
}
|
||||
} while(false);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,35 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f() internal view returns (S storage c) {
|
||||
do {
|
||||
break;
|
||||
c = s;
|
||||
} while(false);
|
||||
}
|
||||
function g() internal view returns (S storage c) {
|
||||
do {
|
||||
if (s.f) {
|
||||
continue;
|
||||
c = s;
|
||||
}
|
||||
else {
|
||||
}
|
||||
} while(false);
|
||||
}
|
||||
function h() internal view returns (S storage c) {
|
||||
do {
|
||||
if (s.f) {
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
c = s;
|
||||
}
|
||||
} while(false);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (87-98): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
// Warning: (223-234): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
// Warning: (440-451): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
@@ -0,0 +1,6 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f() internal view returns (S storage c, S storage d) { c = s; d = s; return; }
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,15 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f() internal pure returns (S storage) { return; }
|
||||
function g() internal view returns (S storage c, S storage) { c = s; return; }
|
||||
function h() internal view returns (S storage, S storage d) { d = s; return; }
|
||||
function i() internal pure returns (S storage, S storage) { return; }
|
||||
function j() internal view returns (S storage, S storage) { return (s,s); }
|
||||
}
|
||||
// ----
|
||||
// Warning: (87-88): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
// Warning: (163-164): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
// Warning: (233-234): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
// Warning: (316-317): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
// Warning: (327-328): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
@@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f() internal view returns (S storage c) {
|
||||
for(c = s;;) {
|
||||
}
|
||||
}
|
||||
function g() internal view returns (S storage c) {
|
||||
for(; (c = s).f;) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,16 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f() internal view returns (S storage c) {
|
||||
for(;; c = s) {
|
||||
}
|
||||
}
|
||||
function g() internal view returns (S storage c) {
|
||||
for(;;) {
|
||||
c = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (87-98): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
// Warning: (182-193): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
@@ -0,0 +1,29 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f(bool flag) internal view returns (S storage c) {
|
||||
if (flag) c = s;
|
||||
else c = s;
|
||||
}
|
||||
function g(bool flag) internal view returns (S storage c) {
|
||||
if (flag) c = s;
|
||||
else { c = s; }
|
||||
}
|
||||
function h(bool flag) internal view returns (S storage c) {
|
||||
if (flag) c = s;
|
||||
else
|
||||
{
|
||||
if (!flag) c = s;
|
||||
else c = s;
|
||||
}
|
||||
}
|
||||
function i() internal view returns (S storage c) {
|
||||
if ((c = s).f) {
|
||||
}
|
||||
}
|
||||
function j() internal view returns (S storage c) {
|
||||
if ((c = s).f && !(c = s).f) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,18 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f(bool flag) internal view returns (S storage c) {
|
||||
if (flag) c = s;
|
||||
}
|
||||
function g(bool flag) internal returns (S storage c) {
|
||||
if (flag) c = s;
|
||||
else
|
||||
{
|
||||
if (!flag) c = s;
|
||||
else s.f = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (96-107): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
// Warning: (186-197): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
@@ -0,0 +1,20 @@
|
||||
contract C {
|
||||
modifier revertIfNoReturn() {
|
||||
_;
|
||||
revert();
|
||||
}
|
||||
modifier ifFlag(bool flag) {
|
||||
if (flag)
|
||||
_;
|
||||
}
|
||||
struct S { uint a; }
|
||||
S s;
|
||||
function f(bool flag) revertIfNoReturn() internal view returns(S storage) {
|
||||
if (flag) return s;
|
||||
}
|
||||
function g(bool flag) revertIfNoReturn() ifFlag(flag) internal view returns(S storage) {
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,22 @@
|
||||
contract C {
|
||||
modifier revertIfNoReturn() {
|
||||
_;
|
||||
revert();
|
||||
}
|
||||
modifier ifFlag(bool flag) {
|
||||
if (flag)
|
||||
_;
|
||||
}
|
||||
struct S { uint a; }
|
||||
S s;
|
||||
function f(bool flag) ifFlag(flag) internal view returns(S storage) {
|
||||
return s;
|
||||
}
|
||||
|
||||
function g(bool flag) ifFlag(flag) revertIfNoReturn() internal view returns(S storage) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (249-250): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
// Warning: (367-368): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
@@ -0,0 +1,12 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f() internal pure returns (S storage) {
|
||||
revert();
|
||||
}
|
||||
function g(bool flag) internal view returns (S storage c) {
|
||||
if (flag) c = s;
|
||||
else revert();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f() internal view returns (S storage c) {
|
||||
(c = s).f && false;
|
||||
}
|
||||
function g() internal view returns (S storage c) {
|
||||
(c = s).f || true;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,18 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f() internal view returns (S storage c) {
|
||||
false && (c = s).f;
|
||||
}
|
||||
function g() internal view returns (S storage c) {
|
||||
true || (c = s).f;
|
||||
}
|
||||
function h() internal view returns (S storage c) {
|
||||
// expect warning, although this is always fine
|
||||
true && (false || (c = s).f);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (87-98): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
// Warning: (176-187): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
// Warning: (264-275): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
@@ -0,0 +1,10 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f() internal pure {}
|
||||
function g() internal view returns (S storage) { return s; }
|
||||
function h() internal view returns (S storage c) { return s; }
|
||||
function i() internal view returns (S storage c) { c = s; }
|
||||
function j() internal view returns (S storage c) { (c) = s; }
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,14 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f(bool flag) internal view returns (S storage c) {
|
||||
flag ? c = s : c = s;
|
||||
}
|
||||
function g(bool flag) internal view returns (S storage c) {
|
||||
flag ? c = s : (c = s);
|
||||
}
|
||||
function h(bool flag) internal view returns (S storage c) {
|
||||
flag ? (c = s).f : (c = s).f;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f(bool flag) internal view returns (S storage c) {
|
||||
flag ? (c = s).f : false;
|
||||
}
|
||||
function g(bool flag) internal view returns (S storage c) {
|
||||
flag ? false : (c = s).f;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (96-107): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
// Warning: (200-211): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
@@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f() internal pure returns (S storage) {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (108-113): "throw" is deprecated in favour of "revert()", "require()" and "assert()".
|
||||
@@ -0,0 +1,12 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f() internal view returns (S storage, uint) {
|
||||
return (s,2);
|
||||
}
|
||||
function g() internal view returns (S storage c) {
|
||||
uint a;
|
||||
(c, a) = f();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,19 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f() internal view returns (S storage c) {
|
||||
while((c = s).f) {
|
||||
}
|
||||
}
|
||||
function g() internal view returns (S storage c) {
|
||||
c = s;
|
||||
while(false) {
|
||||
}
|
||||
}
|
||||
function h() internal view returns (S storage c) {
|
||||
while(false) {
|
||||
}
|
||||
c = s;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
struct S { bool f; }
|
||||
S s;
|
||||
function f() internal view returns (S storage c) {
|
||||
while(false) {
|
||||
c = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (87-98): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
Reference in New Issue
Block a user