aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/first-field-2.c
blob: 2fb98d3c9d728bddf2f7cf5546c7730fbde8c00f (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
/* A toy re-implementation of CPython's object model.  */

#include <stdlib.h>
#include <string.h>

#include "analyzer-decls.h"

typedef struct base_obj base_obj;
typedef struct string_obj string_obj;

struct base_obj
{
  int ob_refcnt;
};

struct string_obj
{
  base_obj str_base;
  size_t str_len;
  char str_buf[];
};

base_obj *alloc_obj (const char *str)
{
  size_t len = strlen (str);
  base_obj *obj = (base_obj *)malloc (sizeof (string_obj) + len + 1);
  if (!obj)
    return NULL;
  obj->ob_refcnt = 1;
  string_obj *str_obj = (string_obj *)obj;
  __analyzer_eval (str_obj->str_base.ob_refcnt == 1); /* { dg-warning "TRUE" } */
  return obj;
}