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

Fixing benchmarks with overflows from nla-digibench #1155

Merged
merged 14 commits into from
Oct 24, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions c/nla-digbench/hard.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
format_version: '2.0'
input_files: 'hard.c'
properties:
- property_file: ../properties/unreach-call.prp
expected_verdict: false
- property_file: ../properties/no-overflow.prp
expected_verdict: true

options:
language: C
Expand Down
61 changes: 61 additions & 0 deletions c/nla-digbench/hardu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
hardware integer division program, by Manna
returns q==A//B
*/

extern void abort(void);
extern void __assert_fail(const char *, const char *, unsigned int, const char *) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__noreturn__));
void reach_error() { __assert_fail("0", "hard.c", 8, "reach_error"); }
extern unsigned int __VERIFIER_nondet_unsigned_int(void);
extern void abort(void);
void assume_abort_if_not(int cond) {
if(!cond) {abort();}
}
void __VERIFIER_assert(int cond) {
if (!(cond)) {
ERROR:
{reach_error();}
}
return;
}

int main() {
unsigned int A, B;
unsigned int r, d, p, q;
A = __VERIFIER_nondet_unsigned_int();
B = __VERIFIER_nondet_unsigned_int();
assume_abort_if_not(B >= 1);

r = A;
d = B;
p = 1;
q = 0;

while (1) {
__VERIFIER_assert(q == 0);
__VERIFIER_assert(r == A);
__VERIFIER_assert(d == B * p);
if (!(r >= d)) break;

d = 2 * d;
p = 2 * p;
}

while (1) {
__VERIFIER_assert(A == q*B + r);
__VERIFIER_assert(d == B*p);

if (!(p != 1)) break;

d = d / 2;
p = p / 2;
if (r >= d) {
r = r - d;
q = q + p;
}
}

__VERIFIER_assert(A == d*q + r);
__VERIFIER_assert(B == d);
return 0;
}
11 changes: 11 additions & 0 deletions c/nla-digbench/hardu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
format_version: '2.0'
input_files: 'hardu.c'
properties:
- property_file: ../properties/unreach-call.prp
expected_verdict: false
- property_file: ../properties/no-overflow.prp
expected_verdict: true

options:
language: C
data_model: ILP32