summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/init/array16.C
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/g++.dg/init/array16.C
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/g++.dg/init/array16.C')
-rw-r--r--gcc/testsuite/g++.dg/init/array16.C112
1 files changed, 112 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/init/array16.C b/gcc/testsuite/g++.dg/init/array16.C
new file mode 100644
index 000000000..188d1a84f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/array16.C
@@ -0,0 +1,112 @@
+// Causes timeout for the MMIX simulator on a 3GHz P4 and we can't
+// have "compile" for some targets and "run" for others.
+// { dg-do run { target { ! mmix-*-* } } }
+// { dg-options "-mstructure-size-boundary=8" { target arm*-*-* } }
+
+// Copyright (C) 2004 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 8 Dec 2004 <nathan@codesourcery.com>
+
+// PR 16681 too much memory used
+// Origin: Matt LaFary <lafary@activmedia.com>
+
+// NOTE: This test assumes that 4M instances of struct ELT can fit into
+// a 5MB array. This isn't true, e.g., with the default
+// arm-none-elf options.
+
+struct elt
+{
+ static int count;
+ static elt*ptr;
+ static int abort;
+ char c;
+
+ elt ();
+ ~elt ();
+
+};
+
+int elt::count;
+elt *elt::ptr;
+int elt::abort;
+
+elt::elt ()
+ :c ()
+{
+ if (count >= 0)
+ {
+ if (!ptr)
+ ptr = this;
+ if (count == 100)
+ throw 2;
+ if (this != ptr)
+ abort = 1;
+ count++;
+ ptr++;
+ }
+}
+
+elt::~elt ()
+{
+ if (count >= 0)
+ {
+ ptr--;
+ count--;
+ if (ptr != this)
+ abort = 2;
+ }
+}
+
+struct foo {
+ elt buffer[4111222];
+ foo() ;
+ bool check () const;
+};
+
+foo::foo ()
+ : buffer()
+{}
+
+bool foo::check () const
+{
+ for (unsigned ix = sizeof (buffer)/ sizeof (buffer[0]); ix--;)
+ if (buffer[ix].c)
+ return false;
+ return true;
+}
+
+void *operator new (__SIZE_TYPE__ size, void *p)
+{
+ return p;
+}
+
+char heap[5000000];
+
+int main ()
+{
+ for (unsigned ix = sizeof (heap); ix--;)
+ heap[ix] = ix;
+
+ try
+ {
+ foo *f = new (heap) foo ();
+ return 1;
+ }
+ catch (...)
+ {
+ if (elt::count)
+ return 2;
+ if (elt::abort)
+ return elt::abort + 3;
+ }
+
+ for (unsigned ix = sizeof (heap); ix--;)
+ heap[ix] = ix;
+
+ elt::count = -1;
+ foo *f = new (heap) foo ();
+ if (!f->check ())
+ return 3;
+ return 0;
+}
+
+