summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-13a.c
blob: d74ef59c7cf35f7a9a93d9d663dc5b09f9d69000 (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
/* { dg-additional-options "-fanalyzer-verbosity=1" } */

#include <stdlib.h>

void
calls_free (void *victim)
{
  free (victim); /* { dg-warning "double-'free' of 'victim'" } */
}

extern void do_stuff (void);

struct foo
{
  void *m_p;
};

static void *  __attribute__((noinline))
test_a (struct foo f)
{
  do_stuff ();

  calls_free (f.m_p);

  do_stuff ();

  return f.m_p;
}

void test_b (void *p)
{
  void *q;
  struct foo f;
  f.m_p = p;
  q = test_a (f);
  calls_free (q); /* { dg-message "passing freed pointer 'q' in call to 'calls_free' from 'test_b'" } */
  do_stuff ();
}