source: CIVL/examples/languageFeatures/pointerAdd2.cvl@ c33bde8

1.23 2.0 main test-branch
Last change on this file since c33bde8 was 3ff27cf, checked in by Manchun Zheng <zmanchun@…>, 11 years ago

updated examples since $assert/$assume has been changed to functions; fixed the model builder for the new side-effect remover.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@2085 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/*************************************************/
2/* FILE: pointerAdd2.cvl
3 AUTHOR: Ziqing Luo
4
5 This example tries to verify 3 d array in general
6 case with iterating all possible values for every
7 symbolic input variable. The reason of why we don't
8 just use symbolic execution is the prover may not be
9 able to prove the assertion in certainty. So we force
10 to iterate all possible values for every input variable.
11*/
12/*************************************************/
13#include <civlc.cvh>
14#include <stdio.h>
15
16$input int N;
17$input int M;
18$input int L;
19$input int x,y,z;
20$input int offset;
21$input int a[N][M][L];
22$assume(0< N && N <= 2);
23$assume(0< M && M <= 2);
24$assume(0< L && L <= 2);
25$assume(0 <= x && x < N);
26$assume(0 <= y && y < M);
27$assume(0 <= z && z < L);
28$assume(offset + x*M*L + y*L + z < M*N*L &&
29 offset + x*M*L + y*L + z >= 0);
30
31void main(){
32 for(int i=0; i<M; i++);
33 for(int i=0; i<N; i++);
34 for(int i=0; i<L; i++);
35 for(int i=0; i<x; i++);
36 for(int i=0; i<y; i++);
37 for(int i=0; i<z; i++);
38 for(int i=0; i<offset; i++);
39
40 int oldTotal = x * M * L + y * L + z;
41 int newTotal = oldTotal + offset;
42 int X,Y,Z; //new indexes
43
44 X = newTotal / (M * L);
45 newTotal = newTotal - X * M * L;
46 Y = newTotal / (L);
47 Z = newTotal - Y * L;
48 $assert((*(&a[x][y][z] + offset) == a[X][Y][Z]));
49
50}
Note: See TracBrowser for help on using the repository browser.