source: CIVL/examples/contracts/contractsMPI/civl_mpi_collectives/pointer_2_int_notes.txt

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

  • Property mode set to 100644
File size: 1.6 KB
Line 
1pointer_t {
2 int b;
3 int offset;
4}
5
6CASE 0:
7requires \valid(p);
8assigns *p;
9ensures *p == 0;
10f(int * p);
11
12PROPOSED SOLUTION 0:
13int H0[1][];
14pointer_t p';
15requires p' == {0, 0};
16assigns H0[p'.b][p'.offset + 0];
17ensures H0[p'.b][p'.offset + 0] == 0;
18p = &H0[p'.b][p'.offset];
19f(p);
20
21##############################################################
22
23CASE 1:
24typedef struct t {
25 int * x;
26} T;
27
28requires \valid(p) && \valid(p->x + 0 .. 10);
29assigns *(p->x);
30ensures (p->x[0]) == 0;
31f(T * p);
32
33PROPOSED SOLUTION 1:
34T H0[1][];
35int H1[2][];
36int p';
37requires p' == {0,0} && H0[p'.b][p'.offset].x' == {1, 0};
38assigns H1[H0[p'][0].x'.b][H0[p'][0].x'.offset + 0];
39ensures H1[H0[p'][0].x'.b][H0[p'][0].x'.offset + 0] == 0;
40p = H0[p'];
41p->x = H1[H0[p'][0].x'];
42f(p);
43
44##############################################################
45
46CASE 2:
47requires \valid(p) || p == MPI_IN_PLACE;
48f(void *p);
49
50PROPOSED_SOLUTION 2:
51char H0[1][];
52int H1[2][];
53int p';
54int MIPS = 1;
55H1[MIPS][0] = MPI_IN_PLACE_SPOT;
56requires p' == 0 || p' == MIPS;
57
58##############################################################
59
60CASE 3:
61requires \valid(p + 0 .. 10) && \valid(p[0 .. 10] + 0 .. 10);
62assigns p[0 .. 10][0 .. 10];
63f(void **p);
64
65PROPOSED_SOLUTION 2:
66int H0[1][]; //'char *' is 'int' as well
67char H1[11][];
68
69requires p' == 0 && FORALL i; 0<=i<=10 ==> H0[p'][i] == 1 + i;
70assigns H1[H0[p'][0 .. 10]][0 .. 10];
71
72##############################################################
73
74Possible patterns of pointer p in expressions:
75p[n] -> H0[p'][n]
76
77p->x -> H0[p'].x
78
79*p -> H0[p'][0]
80
81p + n -> &H0[p'][0] + n
82
83p - q -> UNIMPLEMENTED/ either within an array or UNDEFINED
84
85
86
87
Note: See TracBrowser for help on using the repository browser.