aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/refcounting-1.c
blob: 4eb3a3e6ff20b0df8d6c23bc5912f19d32b6800b (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
#include "analyzer-decls.h"

typedef struct obj {
  int ob_refcnt;
} PyObject;

extern void Py_Dealloc (PyObject *op);

#define Py_INCREF(op)			\
  do {					\
    ((PyObject*)(op))->ob_refcnt++;	\
  } while (0)

#define Py_DECREF(op)                                   \
    do {                                                \
      if (--((PyObject*)(op))->ob_refcnt == 0)		\
	{						\
	  /*Py_Dealloc((PyObject *)(op));*/		\
	}						\
    } while (0)

void test_1 (PyObject *obj)
{
  int orig_refcnt = obj->ob_refcnt;
  Py_INCREF (obj);
  Py_INCREF (obj);
  Py_DECREF (obj);
  Py_INCREF (obj);
  __analyzer_eval (obj->ob_refcnt == orig_refcnt + 2); /* { dg-warning "TRUE" } */
}
/* TODO: uncomment the Py_Dealloc, which leads to two paths.  */