1 // { dg-do run { xfail xstormy16-*-* *-*-darwin* } }
2 // Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc.
3 // Contributed by Nathan Sidwell 6 June 2000 <nathan@codesourcery.com>
5 // Check we can throw a bad_alloc exception when malloc dies.
7 typedef __SIZE_TYPE__ size_t;
8 extern "C" void abort();
9 extern "C" void *memcpy(void *, const void *, size_t);
11 // Assume that STACK_SIZE defined implies a system that does not have a
12 // large data space either, and additionally that we're not linking against
13 // a shared libstdc++ (which requires quite a bit more initialization space).
15 const int arena_size = 256;
18 // FreeBSD with threads requires even more space at initialization time.
19 #include "bits/c++config.h"
20 #include "bits/gthr.h"
21 const int arena_size = 131072;
23 const int arena_size = 32768;
29 size_t size __attribute__((aligned));
32 static char arena[arena_size] __attribute__((aligned));
35 // So we can force a failure when needed.
38 extern "C" void *malloc (size_t size)
40 object *p = reinterpret_cast<object *>(&arena[pos]);
46 size = (size + __alignof__(object) - 1) & - __alignof__(object);
47 pos += size + sizeof(object);
49 // Verify that we didn't run out of memory before getting initialized.
56 extern "C" void free (void *)
60 extern "C" void *realloc (void *p, size_t size)
66 object *o = reinterpret_cast<object *>(p) - 1;
67 size_t old_size = o->size;
77 memcpy (r, p, old_size);
87 void fn_throw() throw(int)
92 void fn_rethrow() throw(int)
99 void fn_catchthrow() throw(int)
109 // FreeBSD with threads fails the test unless each thread primes itself.
110 if (__gthread_active_p())
115 // This was added to test with well-known idiom to detect regressions here
116 // rather than always failing with -pthread.
127 try{fn_catchthrow();}