Skip to content
This repository has been archived by the owner on Oct 3, 2021. It is now read-only.

Commit

Permalink
The assertion in the divbin program is violable hence changed the
Browse files Browse the repository at this point in the history
verdict of the program. Also adding the corrected program divbin2 with
verifiable assertion.
  • Loading branch information
divyeshunadkat committed Nov 15, 2019
1 parent 1ca0202 commit 0f331e9
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion c/nla-digbench/divbin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ format_version: '1.0'
input_files: 'divbin.i'
properties:
- property_file: ../properties/unreach-call.prp
expected_verdict: true
expected_verdict: false
48 changes: 48 additions & 0 deletions c/nla-digbench/divbin2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
A division algorithm, by Kaldewaij
returns A//B
*/

#include <limits.h>

extern void __VERIFIER_error() __attribute__((__noreturn__));
extern unsigned __VERIFIER_nondet_unsigned_int(void);
extern void __VERIFIER_assume(int expression);
void __VERIFIER_assert(int cond) {
if (!(cond)) {
ERROR:
__VERIFIER_error();
}
return;
}

int main() {
unsigned A, B;
unsigned q, r, b;
A = __VERIFIER_nondet_unsigned_int();
B = 1;

q = 0;
r = A;
b = B;

while (1) {
if (!(r >= b)) break;
b = 2 * b;
}

while (1) {
__VERIFIER_assert(A == q * b + r);
if (!(b != B)) break;

q = 2 * q;
b = b / 2;
if (r >= b) {
q = q + 1;
r = r - b;
}
}

__VERIFIER_assert(A == q * b + r);
return 0;
}
35 changes: 35 additions & 0 deletions c/nla-digbench/divbin2.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
extern void __VERIFIER_error() __attribute__((__noreturn__));
extern unsigned __VERIFIER_nondet_unsigned_int(void);
extern void __VERIFIER_assume(int expression);
void __VERIFIER_assert(int cond) {
if (!(cond)) {
ERROR:
__VERIFIER_error();
}
return;
}
int main() {
unsigned A, B;
unsigned q, r, b;
A = __VERIFIER_nondet_unsigned_int();
B = 1;
q = 0;
r = A;
b = B;
while (1) {
if (!(r >= b)) break;
b = 2 * b;
}
while (1) {
__VERIFIER_assert(A == q * b + r);
if (!(b != B)) break;
q = 2 * q;
b = b / 2;
if (r >= b) {
q = q + 1;
r = r - b;
}
}
__VERIFIER_assert(A == q * b + r);
return 0;
}
5 changes: 5 additions & 0 deletions c/nla-digbench/divbin2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
format_version: '1.0'
input_files: 'divbin2.i'
properties:
- property_file: ../properties/unreach-call.prp
expected_verdict: true

0 comments on commit 0f331e9

Please sign in to comment.