aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/malloc-dedupe-1.c
blob: 233ab485b5afb37e8d3633ebaad8d22d3f9e79e1 (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
#include <stdlib.h>

extern void foo (void);
extern void bar (void);

void test_1 (int flag, int n);

void caller_1_of_test_1 (int n)
{
  test_1 (1, n); /* { dg-bogus "test_1" } */
  test_1 (0, n); /* { dg-bogus "test_1" } */
}

void __attribute__((noinline))
test_1 (int flag, int n)
{
  int *ptr = (int *)malloc (sizeof (int));

  if (flag)
    {
      int i;
      for (i = 0; i < n; i++)
	foo ();
    }
  else
    bar ();

  free (ptr);
  free (ptr); /* { dg-warning "double-'free'" } */
  /* FIXME: we get duplicates intraprocedurally, as there are two paths
     through the function.
     The calls in test_2 also generate additional duplicates.
     How to verify lack of duplicates?
     Putting a bogus on the interprocedual one detects that, at least.  */

  if (flag)
    foo ();
  else
    bar ();
}

void caller_2_of_test_1 (int n)
{
  test_1 (1, n); /* { dg-bogus "test_1" } */
  test_1 (0, n); /* { dg-bogus "test_1" } */
}