public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6651] New testcase Date: Tue, 14 Mar 2023 07:29:38 +0000 (GMT) [thread overview] Message-ID: <20230314072938.021823858428@sourceware.org> (raw) https://gcc.gnu.org/g:e17936f842d2885447b6b8b82c2fb9cbf2679d7e commit r13-6651-ge17936f842d2885447b6b8b82c2fb9cbf2679d7e Author: Richard Biener <rguenther@suse.de> Date: Tue Mar 14 08:25:52 2023 +0100 New testcase This is a reduced testcase for an issue I ran into when trying to improve PTA compile-time further, there wasn't any C family runfail in the testsuite for this. * g++.dg/torture/20230313.C: New testcase. Diff: --- gcc/testsuite/g++.dg/torture/20230313.C | 109 ++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/gcc/testsuite/g++.dg/torture/20230313.C b/gcc/testsuite/g++.dg/torture/20230313.C new file mode 100644 index 00000000000..d1f348003bd --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/20230313.C @@ -0,0 +1,109 @@ +/* { dg-do run } */ +/* { dg-additional-options "-fno-exceptions -fno-rtti" } */ + +extern "C" void free (void *); +void fancy_abort () { __builtin_abort (); } +struct vec_prefix +{ + unsigned m_alloc : 1; + unsigned m_using_auto_storage : 1; + unsigned m_num; +}; +struct vl_ptr +; +struct va_heap +{ + typedef vl_ptr default_layout; +}; +template<typename , + typename A , + typename = typename A::default_layout> +struct vec +; +template<typename T, typename A> +struct vec<T, A, int> +{ + T & operator[] (unsigned ix) + { + int *__trans_tmp_2; + !m_vecpfx.m_num ? fancy_abort (), 0 : 0; + __trans_tmp_2 = reinterpret_cast <T *> (this + 1); + return __trans_tmp_2[ix]; + } + bool iterate (unsigned , T *ptr) { + *ptr = 0; + return false; + } + void embedded_init (unsigned , unsigned num, unsigned aut) + { + m_vecpfx.m_alloc = + m_vecpfx.m_using_auto_storage = aut; + m_vecpfx.m_num = num; + } + void quick_grow (unsigned len) + { + !m_vecpfx.m_alloc ? fancy_abort (), 0 : m_vecpfx.m_num = len; + } + vec_prefix m_vecpfx; +}; +template<typename T, int N > +struct auto_vec : vec<T, va_heap> +{ + auto_vec () + { + m_auto.embedded_init (N, 0, 1); + long off = (char *) &m_auto - (char *) this; + this->m_vec = (vec<T, va_heap, int> *) ((char *) this + off); + } + ~auto_vec () + { + this->release (); + } + vec<T, va_heap, int> m_auto; + char m_data; +}; +template<typename T> +struct vec<T, va_heap> +{ +void +release () +{ + bool __trans_tmp_1 = m_vec ? m_vec->m_vecpfx.m_using_auto_storage : false; + if (__trans_tmp_1) + return; + vec<int, va_heap, int> *&v = m_vec; + free (m_vec); + v = nullptr; +} +T &operator[] (unsigned ix) { return (*m_vec)[ix]; } +bool +iterate (unsigned ix, T *ptr) { + m_vec->iterate (ix, ptr); + return false; +} +void +quick_grow (unsigned len) +{ + m_vec->quick_grow (len); +} + vec<T, va_heap, int> *m_vec; +}; +void test_auto_alias () +{ + volatile int i = 1; + auto_vec<int, 8> v; + v.quick_grow (2); + v[0] = 1; + v[1] = 2; + int val; + for (int ix = i; v.iterate (ix, &val); ix++) + if (val != 2) + __builtin_abort (); + if (val != 0) + __builtin_abort (); +} +int main() +{ + test_auto_alias (); + return 0; +}
reply other threads:[~2023-03-14 7:29 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230314072938.021823858428@sourceware.org \ --to=rguenth@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).