Warn about unreachable code.

This commit is contained in:
Daniel Kirchner committed 2019-01-10 10:36:50 +01:00
1 parent 63319cfdcd
commit 0dfd4a726e
27 files changed
+258 -12

No files matched your search

@@ -0,0 +1,6 @@
contract C {
function f() public pure {
return;
// unreachable comment
}
}
@@ -0,0 +1,8 @@
contract C {
function f() public pure {
if (false) {
return; // unreachable, but not yet detected
}
return;
}
}
@@ -0,0 +1,12 @@
contract C {
function f() public pure {
do {
uint a = 42; a;
continue;
return; // this is unreachable
} while(false);
return; // this is still reachable
}
}
// ----
// Warning: (119-126): Unreachable code.
@@ -0,0 +1,8 @@
contract C {
function f() public pure returns (uint) {
return 0;
return 0;
}
}
// ----
// Warning: (85-93): Unreachable code.
@@ -0,0 +1,8 @@
contract C {
function f() public pure {
revert();
revert();
}
}
// ----
// Warning: (70-78): Unreachable code.
@@ -0,0 +1,12 @@
contract C {
function f() public pure {
for (uint a = 0; a < 1; a++) {
break;
uint b = 42; b;
}
return;
}
}
// ----
// Warning: (76-79): Unreachable code.
// Warning: (114-128): Unreachable code.
@@ -0,0 +1,12 @@
contract C {
function f(bool c) public pure {
if (c) {
return;
} else {
return;
}
return; // unreachable
}
}
// ----
// Warning: (142-149): Unreachable code.
@@ -0,0 +1,8 @@
contract C {
function f() public pure {
revert();
uint a = 0; a;
}
}
// ----
// Warning: (70-83): Unreachable code.
@@ -0,0 +1,8 @@
contract C {
function f() public pure {
revert();
for(int i = 0; i < 3; i++) { f(); }
}
}
// ----
// Warning: (70-105): Unreachable code.
@@ -0,0 +1,12 @@
contract C {
function f() public pure {
uint a = 0;
while (a < 100) {
a++;
break;
a--;
}
}
}
// ----
// Warning: (138-141): Unreachable code.
@@ -0,0 +1,11 @@
contract C {
function f() public pure {
while(true) {
continue;
return;
}
return; // this is unreachable as well, but currently undetected (needs to consider constant condition "true")
}
}
// ----
// Warning: (100-107): Unreachable code.