File: arith_pointer.c

package info (click to toggle)
frama-c 20220511-manganese-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 66,492 kB
  • sloc: ml: 278,834; ansic: 47,093; sh: 4,823; makefile: 3,613; javascript: 2,436; python: 1,919; perl: 897; lisp: 293; xml: 62
file content (71 lines) | stat: -rw-r--r-- 1,025 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* run.config*
   STDOPT: +"-ulevel 22" +"-then -eva-no-warn-pointer-subtraction"
*/


// #include <stdio.h>
int a;
int t[25];
void main1()
{
  int i,j;
  for (i=-10; i< 10; i++)
    {
      t[i+10] = (int*)(i+10)-(int*)10;
//      printf("%d\n",(int*)(i+10)-(int*)10);
      }
  j = -i;
//  printf("%d %d\n",(int)&a,(int)(&a-(int*)0));
}

volatile int vol;

void main2() {
  int x, y;
  int d;
  int *p1 = &x;
  int *p2 = &y;

  if (vol) {
    d = p1 - p2;
    Frama_C_show_each(d);
  }

  p2 = (char*)&x + 3;
  d = p1 - p2;
  Frama_C_show_each(d);

  p2 = (char*)&x - 3;
  d = p1 - p2;
  Frama_C_show_each(d);

  if (vol) {
    p1 = &x+1;
    p2 = &x+7;
  } else {
    p1 = &y+8;
    p2 = &y+19;
  }
  d = p2 - p1;
  Frama_C_show_each(d);
  d = p2 - p2;
  Frama_C_show_each(d);

  p1 = &x + (int)&x;
  p2 = &x;
  d = p2 - p1;
  Frama_C_show_each(d);

  int i = vol;
  //@ assert 0 <= i <= 4;
  p1 = &x + i;
  p2 = p1 + 1;
  d = p2 - p1;
  Frama_C_show_each(d);
  //@ assert d == 1;
}

void main() {
  main1();
  main2();
}