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

1.23 2.0 main test-branch
Last change on this file since b144b24 was d010d61, checked in by Ziqing Luo <ziqing@…>, 12 years ago

new pointerAdd () function and couple of examples

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

  • Property mode set to 100644
File size: 1.4 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.h>
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 realIndex = x * M * L + y * L + z;
41 int finalIndex = realIndex + offset;
42 int X,Y,Z; //new indexes
43
44 X = finalIndex / (M * L);
45 finalIndex = finalIndex - X * M * L;
46 Y = finalIndex / (L);
47 Z = finalIndex - Y * L;
48
49 $assert(*(&a[x][y][z] + offset) == a[X][Y][Z]);
50
51}
Note: See TracBrowser for help on using the repository browser.