From 00b168bf32b9a71978a3e411bf0cc602b9091d3e Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Mon, 1 Jun 2020 16:57:57 -0400 Subject: [PATCH 195/315] FIXME: move first-field-* to testsuite; fix them up --- first-field-1.c | 24 ------------------ gcc/testsuite/gcc.dg/analyzer/first-field-1.c | 24 ++++++++++++++++++ .../testsuite/gcc.dg/analyzer/first-field-2.c | 25 +++++-------------- 3 files changed, 30 insertions(+), 43 deletions(-) delete mode 100644 first-field-1.c create mode 100644 gcc/testsuite/gcc.dg/analyzer/first-field-1.c rename first-field-2.c => gcc/testsuite/gcc.dg/analyzer/first-field-2.c (58%) diff --git a/first-field-1.c b/first-field-1.c deleted file mode 100644 index 0754cf7f884..00000000000 --- a/first-field-1.c +++ /dev/null @@ -1,24 +0,0 @@ -/* A toy re-implementation of CPython's object model. */ - -typedef struct base_obj -{ - int m_first; - int m_second; -} base_obj; - -typedef struct sub_obj -{ - base_obj base; -} sub_obj; - -void test (sub_obj *sub) -{ - sub->base.m_first = 1; - sub->base.m_second = 2; - __analyzer_eval (sub->base.m_first == 1); - __analyzer_eval (sub->base.m_second == 2); - - base_obj *base = (struct base_obj *)sub; - __analyzer_eval (base->m_first == 1); - __analyzer_eval (base->m_second == 2); -} diff --git a/gcc/testsuite/gcc.dg/analyzer/first-field-1.c b/gcc/testsuite/gcc.dg/analyzer/first-field-1.c new file mode 100644 index 00000000000..8b71e1abcae --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/first-field-1.c @@ -0,0 +1,24 @@ +#include "analyzer-decls.h" + +typedef struct base_obj +{ + int m_first; + int m_second; +} base_obj; + +typedef struct sub_obj +{ + base_obj base; +} sub_obj; + +void test (sub_obj *sub) +{ + sub->base.m_first = 1; + sub->base.m_second = 2; + __analyzer_eval (sub->base.m_first == 1); /* { dg-warning "TRUE" } */ + __analyzer_eval (sub->base.m_second == 2); /* { dg-warning "TRUE" } */ + + base_obj *base = (struct base_obj *)sub; + __analyzer_eval (base->m_first == 1); /* { dg-warning "TRUE" } */ + __analyzer_eval (base->m_second == 2); /* { dg-warning "TRUE" } */ +} diff --git a/first-field-2.c b/gcc/testsuite/gcc.dg/analyzer/first-field-2.c similarity index 58% rename from first-field-2.c rename to gcc/testsuite/gcc.dg/analyzer/first-field-2.c index 59e73ae2585..2fb98d3c9d7 100644 --- a/first-field-2.c +++ b/gcc/testsuite/gcc.dg/analyzer/first-field-2.c @@ -1,8 +1,9 @@ /* A toy re-implementation of CPython's object model. */ -#include -#include #include +#include + +#include "analyzer-decls.h" typedef struct base_obj base_obj; typedef struct string_obj string_obj; @@ -12,11 +13,6 @@ struct base_obj int ob_refcnt; }; -struct type_obj -{ - base_obj tp_base; -}; - struct string_obj { base_obj str_base; @@ -24,23 +20,14 @@ struct string_obj char str_buf[]; }; -type_obj type_type = { - { &type_type, 1}, -}; - -type_obj str_type = { - { &type_type, 1}, -}; - -base_obj *alloc_obj (type_obj *ob_type, size_t sz) +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_type = &str_type; obj->ob_refcnt = 1; string_obj *str_obj = (string_obj *)obj; - __analyzer_eval (str_obj->str_base.ob_type == &str_type); - __analyzer_eval (str_obj->str_base.ob_refcnt == 1); + __analyzer_eval (str_obj->str_base.ob_refcnt == 1); /* { dg-warning "TRUE" } */ + return obj; } -- 2.26.2