File: undefined_sequence.i

package info (click to toggle)
frama-c 20161101%2Bsilicon%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 42,324 kB
  • ctags: 35,695
  • sloc: ml: 200,142; ansic: 31,465; makefile: 2,334; sh: 1,643; lisp: 259; python: 85; asm: 26
file content (68 lines) | stat: -rw-r--r-- 1,300 bytes parent folder | download | duplicates (5)
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
/* run.config*
   STDOPT: #"-unspecified-access"
   STDOPT: #"-no-unspecified-access"
*/
/* detection of undefined behavior for read/write accesses
   in unspecified order
*/
int G[10]; volatile int c;

int f (int x) { return x+1;}
int g (int x) { return x+2;}

int r, H;
int h(int i)
{
  if (c) r = r++; //UB
  i = r++; //Not UB
  H = i;
  return i;
}

int func(int x, int y) { return x + y; }

//volatile int c;

int ub_ret(void) {
  int d = 5;
  return d + (d=0); // UB
}

int main (int a) {
  int x, *y, i,j;
  x = 0;
  y = &x;
  if (c) i=(x=0)+(*y=1); // UB
  for (i=0; i < 10; i++) G[i] = i;
  i=j=0;
  while (j<10 && i<10) G[j++] = G[i++];
  i=j=0;
  while (j<10 && i<10) G[j++] += G[i++];
  i=j=0;
  if (c) {
    while(j<9 && i<9) {
      if (c) G[j] = G[j++]; // UB
      if (c) G[i++] = G[i]; // UB
    }}
  i=j=0;
  if (c) {
    while(j<9 && i<9) {
      if (c) G[j] += G[j++]; // UB
      if (c) G[i++] += G[i]; // UB
    }}
  if (c) i = f(g(3)+x) + x++; //UB
  *y = f(g(3)+x); // no UB: x is read to write to x (through an alias)
  if (a)
    r = h(1) + h(2); // missing alarm!

  y = &G[2];

  *y =  (G[2] < (func((0U ||
         (((G[2] ^ G[2]) <= G[2]) < ((*y) || G[2]))), 5)));

  int (*my_f) (int) = f;
  
  if (c) G[9] = ub_ret();
  
  return (c ? (my_f=g, f(1)) + my_f(2) : 0);
}