mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[SMTChecker] Refactor CHC loops and add if blocks
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f() public pure {
|
||||
uint x;
|
||||
do {
|
||||
break;
|
||||
x = 1;
|
||||
} while (x == 0);
|
||||
assert(x == 0);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (104-109): Unreachable code.
|
||||
// Warning: (122-128): Unreachable code.
|
||||
@@ -0,0 +1,19 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f() public pure {
|
||||
uint a = 0;
|
||||
while (true) {
|
||||
do {
|
||||
break;
|
||||
a = 2;
|
||||
} while (true);
|
||||
a = 1;
|
||||
break;
|
||||
}
|
||||
assert(a == 1);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (128-133): Unreachable code.
|
||||
// Warning: (147-151): Unreachable code.
|
||||
@@ -0,0 +1,20 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f() public pure {
|
||||
uint a = 0;
|
||||
while (true) {
|
||||
do {
|
||||
break;
|
||||
a = 2;
|
||||
} while (true);
|
||||
a = 1;
|
||||
break;
|
||||
}
|
||||
assert(a == 2);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (128-133): Unreachable code.
|
||||
// Warning: (147-151): Unreachable code.
|
||||
// Warning: (180-194): Assertion violation happens here
|
||||
@@ -0,0 +1,16 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f() public pure {
|
||||
uint x;
|
||||
do {
|
||||
break;
|
||||
x = 1;
|
||||
} while (x == 0);
|
||||
assert(x == 1);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (104-109): Unreachable code.
|
||||
// Warning: (122-128): Unreachable code.
|
||||
// Warning: (133-147): Assertion violation happens here
|
||||
@@ -0,0 +1,14 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f() public pure {
|
||||
uint x;
|
||||
do {
|
||||
continue;
|
||||
x = 1;
|
||||
} while (x == 0);
|
||||
assert(x == 0);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (107-112): Unreachable code.
|
||||
@@ -0,0 +1,17 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C
|
||||
{
|
||||
function f(uint x, bool b) public pure {
|
||||
require(x < 10);
|
||||
for (; x < 10; ) {
|
||||
if (b)
|
||||
++x;
|
||||
else {
|
||||
x = 20;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(x >= 10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C
|
||||
{
|
||||
function f(uint x, bool b) public pure {
|
||||
for (; x < 10; ) {
|
||||
if (b)
|
||||
++x;
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Fails because the loop might break.
|
||||
assert(x >= 10);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (201-216): Assertion violation happens here
|
||||
@@ -0,0 +1,15 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C
|
||||
{
|
||||
function f(uint x, bool b) public pure {
|
||||
require(x < 10);
|
||||
for (; x < 10; ++x) {
|
||||
if (b) {
|
||||
x = 20;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
assert(x > 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C
|
||||
{
|
||||
function f(uint x, bool b) public pure {
|
||||
require(x < 10);
|
||||
for (; x < 10; ) {
|
||||
if (b) {
|
||||
x = 20;
|
||||
continue;
|
||||
}
|
||||
++x;
|
||||
}
|
||||
assert(x > 15);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (185-199): Assertion violation happens here
|
||||
@@ -0,0 +1,12 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C
|
||||
{
|
||||
function f(uint x) public pure {
|
||||
for (x = 0; x < 10; ++x)
|
||||
break;
|
||||
assert(x == 0);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (102-105): Unreachable code.
|
||||
@@ -12,10 +12,6 @@ contract C
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Assertion is safe but break is unsupported for now
|
||||
// so knowledge is erased.
|
||||
assert(x >= 10);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (274-289): Assertion violation happens here
|
||||
|
||||
@@ -3,20 +3,14 @@ pragma experimental SMTChecker;
|
||||
contract C
|
||||
{
|
||||
function f(uint x, bool b) public pure {
|
||||
require(x < 100);
|
||||
require(x < 10);
|
||||
while (x < 10) {
|
||||
if (b) {
|
||||
x = 15;
|
||||
x = 20;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
x = 20;
|
||||
|
||||
++x;
|
||||
}
|
||||
// Should be safe, but fails due to continue being unsupported
|
||||
// and erasing all knowledge.
|
||||
assert(x >= 15);
|
||||
assert(x >= 10);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (294-309): Assertion violation happens here
|
||||
|
||||
@@ -8,9 +8,9 @@ contract C
|
||||
if (b) {
|
||||
x = 15;
|
||||
continue;
|
||||
x = 200;
|
||||
}
|
||||
else
|
||||
x = 20;
|
||||
x = 20;
|
||||
|
||||
}
|
||||
// Fails due to the if.
|
||||
@@ -18,4 +18,5 @@ contract C
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (223-238): Assertion violation happens here
|
||||
// Warning: (169-176): Unreachable code.
|
||||
// Warning: (227-242): Assertion violation happens here
|
||||
|
||||
@@ -9,11 +9,8 @@ contract C
|
||||
break;
|
||||
++x;
|
||||
}
|
||||
// Assertion is safe but break is unsupported for now
|
||||
// so knowledge is erased.
|
||||
assert(x == 1);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (128-131): Unreachable code.
|
||||
// Warning: (224-238): Assertion violation happens here
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C
|
||||
{
|
||||
function f(uint x) public pure {
|
||||
x = 0;
|
||||
while (x < 10)
|
||||
break;
|
||||
assert(x == 0);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (98-104): Condition is always true.
|
||||
@@ -0,0 +1,30 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C
|
||||
{
|
||||
function f(uint x, uint y, bool b, bool c) public pure {
|
||||
require(x < 10);
|
||||
while (x < 10) {
|
||||
if (b) {
|
||||
++x;
|
||||
if (x == 10)
|
||||
x = 15;
|
||||
}
|
||||
else {
|
||||
require(y < 10);
|
||||
while (y < 10) {
|
||||
if (c)
|
||||
++y;
|
||||
else {
|
||||
y = 20;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(y >= 10);
|
||||
x = 15;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(x >= 15);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C
|
||||
{
|
||||
function f(uint x, uint y, bool b, bool c) public pure {
|
||||
require(x < 10);
|
||||
while (x < 10) {
|
||||
if (b) {
|
||||
++x;
|
||||
if (x == 10)
|
||||
x = 15;
|
||||
}
|
||||
else {
|
||||
require(y < 10);
|
||||
while (y < 10) {
|
||||
if (c)
|
||||
++y;
|
||||
else {
|
||||
y = 20;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(y >= 15);
|
||||
x = 15;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(x >= 20);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (329-344): Assertion violation happens here
|
||||
// Warning: (380-395): Assertion violation happens here
|
||||
@@ -0,0 +1,28 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C
|
||||
{
|
||||
function f(uint x, uint y, bool b, bool c) public pure {
|
||||
require(x < 10);
|
||||
while (x < 10) {
|
||||
if (b) {
|
||||
x = 20;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
require(y < 10);
|
||||
while (y < 10) {
|
||||
if (c) {
|
||||
y = 20;
|
||||
continue;
|
||||
}
|
||||
y = 15;
|
||||
break;
|
||||
}
|
||||
assert(y >= 15);
|
||||
x = y;
|
||||
}
|
||||
}
|
||||
assert(x >= 15);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C
|
||||
{
|
||||
function f(uint x, uint y, bool b, bool c) public pure {
|
||||
require(x < 10);
|
||||
while (x < 10) {
|
||||
if (b) {
|
||||
x = 15;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
require(y < 10);
|
||||
while (y < 10) {
|
||||
if (c) {
|
||||
y = 20;
|
||||
continue;
|
||||
}
|
||||
y = 15;
|
||||
break;
|
||||
}
|
||||
assert(y >= 20);
|
||||
x = y;
|
||||
}
|
||||
}
|
||||
assert(x >= 20);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (323-338): Assertion violation happens here
|
||||
// Warning: (362-377): Assertion violation happens here
|
||||
Reference in New Issue
Block a user