File: boxed-int-1.c

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (170 lines) | stat: -rw-r--r-- 3,819 bytes parent folder | download | duplicates (2)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* { dg-skip-if "" { *-*-* } { "-fno-fat-lto-objects" } { "" } } */

#include "../analyzer-decls.h"

typedef struct boxed_int { int value; } boxed_int;

extern boxed_int boxed_int_add (boxed_int a, boxed_int b);
extern boxed_int boxed_int_mul (boxed_int a, boxed_int b);

boxed_int  __attribute__((noinline))
noinline_boxed_int_add (boxed_int a, boxed_int b)
{
  boxed_int result;
  result.value = a.value + b.value;
  return result;
}

static inline boxed_int
inline_boxed_int_add (boxed_int a, boxed_int b)
{
  boxed_int result;
  result.value = a.value + b.value;
  return result;
}

boxed_int
test_1 (boxed_int a, boxed_int b)
{
  boxed_int result = boxed_int_add (boxed_int_mul (a, a),
				    boxed_int_mul (b, b));
  return result;
}

void
test_2a (void)
{
  boxed_int arr[4];
  arr[0].value = 1;
  arr[1].value = 2;
  arr[2].value = 3;
  arr[3].value = 4;
  boxed_int sum;
  sum.value = arr[0].value + arr[1].value + arr[2].value + arr[3].value;
  __analyzer_eval (sum.value == 10); /* { dg-warning "TRUE" } */
}

void
test_2b (void)
{
  boxed_int a, b, c, d;
  a.value = 1;
  b.value = 2;
  c.value = 3;
  d.value = 4;
  boxed_int sum;
  sum.value = a.value + b.value + c.value + d.value;
  __analyzer_eval (sum.value == 10); /* { dg-warning "TRUE" } */
}

void
test_2c (void)
{
  boxed_int a, b, c, d;
  a.value = 1;
  b.value = 2;
  c.value = 3;
  d.value = 4;
  boxed_int sum = inline_boxed_int_add (inline_boxed_int_add (a, b),
					inline_boxed_int_add (c, d));
  __analyzer_eval (sum.value == 10); /* { dg-warning "TRUE" } */
}

void
test_2d (void)
{
  boxed_int a, b, c, d;
  a.value = 1;
  b.value = 2;
  c.value = 3;
  d.value = 4;
  boxed_int sum = noinline_boxed_int_add (noinline_boxed_int_add (a, b),
					  noinline_boxed_int_add (c, d));
  __analyzer_eval (sum.value == 10); /* { dg-warning "TRUE" } */
}

/* Pointer to a local.  */

void test_4 (void)
{
  boxed_int i;
  int *p = &i.value;
  i.value = 1;
  *p = 2;
  __analyzer_eval (i.value == 2); /* { dg-warning "TRUE" } */
}

/* Local array.  */

void test_5 (void)
{
  boxed_int a[10];
  a[3].value = 5; /* ARRAY_REF.  */
  __analyzer_eval (a[3].value == 5); /* { dg-warning "TRUE" } */
}

/* Local array, but using an unknown index.  */

void test_5a (int idx)
{
  boxed_int a[10];
  a[idx].value = 5; /* ARRAY_REF.  */
  __analyzer_eval (a[idx].value == 5); /* { dg-warning "TRUE" } */
}

/* Array passed in as a param.  */

void test_6 (boxed_int a[10])
{
  /* POINTER_PLUS_EXPR then a MEM_REF.  */
  __analyzer_eval (a[3].value == 42); /* { dg-warning "UNKNOWN" } */
  a[3].value = 42;
  __analyzer_eval (a[3].value == 42); /* { dg-warning "TRUE" } */
}

/* Array passed in as a param ptr.  */

void test_7 (boxed_int *a)
{
  __analyzer_eval (a[3].value == 42); /* { dg-warning "UNKNOWN" } */
  a[3].value = 42;
  __analyzer_eval (a[3].value == 42); /* { dg-warning "TRUE" } */
}

/* Globals.  */

boxed_int glob_a;

void test_10 (void)
{
  __analyzer_eval (glob_a.value == 42); /* { dg-warning "UNKNOWN" } */
  glob_a.value = 42;
  __analyzer_eval (glob_a.value == 42); /* { dg-warning "TRUE" } */
}

/* Use of uninit value.  */
int test_12a (void)
{
  boxed_int i; /* { dg-message "region created on stack here" } */
  return i.value; /* { dg-warning "use of uninitialized value 'i.value'" } */
}

/* Use of uninit value.  */
boxed_int test_12b (void)
{
  boxed_int i; /* { dg-message "region created on stack here" } */
  return i; /* { dg-warning "use of uninitialized value '\[^\n\r\]*'" } */
}

void test_loop (void)
{
  boxed_int i;

  __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */

  for (i.value=0; i.value<256; i.value++) {
      __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
  }

  __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
}