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

Commit

Permalink
Merge pull request #919 from divyeshunadkat/divbin
Browse files Browse the repository at this point in the history
Corrected divbin verdict (from #808) and its correct version
  • Loading branch information
dbeyer committed Nov 16, 2019
2 parents b8ed4d4 + 0f331e9 commit b6bdfde
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 b6bdfde

Please sign in to comment.