aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/pr93695-1.c
blob: e0500c49be727bab0e49564492bd386fb6fd0587 (plain)
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
/* { dg-additional-options "-Wno-analyzer-too-complex" } */
/* TODO: remove the need for this option (PR analyzer/93695).  */

#define NELEMS 10
#define ARRAY_SIZE(a) (sizeof (a) / sizeof (a[0]))

void
test_1 (void)
{
  int *p[NELEMS];
  int i;

  for (i = 0; i < ARRAY_SIZE (p); ++i)
    p[i] = __builtin_malloc (sizeof (i));

  for (i = 0; i < ARRAY_SIZE (p); ++i)
    __builtin_free (p [i]);
}

void
test_2 (int n)
{
  int **p;
  int i;

  p = (int **)__builtin_malloc (sizeof (int *) * n);
  if (!p)
    return;

  for (i = 0; i < n; ++i)
    p[i] = __builtin_malloc (sizeof (i));

  for (i = 0; i < n; ++i)
    __builtin_free (p [i]);

  __builtin_free (p);
}

void
test_3 (int **p, int n)
{
  int i;
  for (i = 0; i < n; ++i)
    p[i] = __builtin_malloc (sizeof (i));
}

void
test_4 (void **p, int n)
{
  int i;
  for (i = 0; i < n; ++i)
    __builtin_free (p[i]);
}