| 1 |
/* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */ |
| 2 |
|
| 3 |
/* A toy re-implementation of CPython's object model. */ |
| 4 |
|
| 5 |
#include <stdlib.h> |
| 6 |
#include <string.h> |
| 7 |
|
| 8 |
#include "../../gcc.dg/analyzer/analyzer-decls.h" |
| 9 |
|
| 10 |
typedef struct base_obj base_obj; |
| 11 |
typedef struct string_obj string_obj; |
| 12 |
|
| 13 |
struct base_obj |
| 14 |
{ |
| 15 |
int ob_refcnt; |
| 16 |
}; |
| 17 |
|
| 18 |
struct string_obj |
| 19 |
{ |
| 20 |
base_obj str_base; |
| 21 |
size_t str_len; |
| 22 |
char str_buf[]; |
| 23 |
}; |
| 24 |
|
| 25 |
base_obj *alloc_obj (const char *str) |
| 26 |
{ |
| 27 |
size_t len = strlen (str); |
| 28 |
base_obj *obj = (base_obj *)malloc (sizeof (string_obj) + len + 1); |
| 29 |
if (!obj) |
| 30 |
return NULL; |
| 31 |
obj->ob_refcnt = 1; |
| 32 |
string_obj *str_obj = (string_obj *)obj; |
| 33 |
__analyzer_eval (str_obj->str_base.ob_refcnt == 1); /* { dg-warning "TRUE" } */ |
| 34 |
return obj; |
| 35 |
} |