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

Corrected divbin verdict (from #808) and its correct version #919

Merged
merged 1 commit into from
Nov 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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