| 1 |
// Causes timeout for the MMIX simulator on a 3GHz P4 and we can't |
| 2 |
// have "compile" for some targets and "run" for others. |
| 3 |
// { dg-do run { target { ! mmix-*-* } } } |
| 4 |
|
| 5 |
// Copyright (C) 2004 Free Software Foundation, Inc. |
| 6 |
// Contributed by Nathan Sidwell 8 Dec 2004 <[email protected]> |
| 7 |
|
| 8 |
// PR 16681 too much memory used |
| 9 |
// Origin: Matt LaFary <[email protected]> |
| 10 |
|
| 11 |
// NOTE: This test assumes that 4M instances of struct ELT can fit into |
| 12 |
// a 5MB array. |
| 13 |
|
| 14 |
struct elt |
| 15 |
{ |
| 16 |
static int count; |
| 17 |
static elt*ptr; |
| 18 |
static int abort; |
| 19 |
char c; |
| 20 |
|
| 21 |
elt (); |
| 22 |
~elt (); |
| 23 |
|
| 24 |
}; |
| 25 |
|
| 26 |
int elt::count; |
| 27 |
elt *elt::ptr; |
| 28 |
int elt::abort; |
| 29 |
|
| 30 |
elt::elt () |
| 31 |
:c () |
| 32 |
{ |
| 33 |
if (count >= 0) |
| 34 |
{ |
| 35 |
if (!ptr) |
| 36 |
ptr = this; |
| 37 |
if (count == 100) |
| 38 |
throw 2; |
| 39 |
if (this != ptr) |
| 40 |
abort = 1; |
| 41 |
count++; |
| 42 |
ptr++; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
elt::~elt () |
| 47 |
{ |
| 48 |
if (count >= 0) |
| 49 |
{ |
| 50 |
ptr--; |
| 51 |
count--; |
| 52 |
if (ptr != this) |
| 53 |
abort = 2; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
struct foo { |
| 58 |
elt buffer[4111222]; |
| 59 |
foo() ; |
| 60 |
bool check () const; |
| 61 |
}; |
| 62 |
|
| 63 |
foo::foo () |
| 64 |
: buffer() |
| 65 |
{} |
| 66 |
|
| 67 |
bool foo::check () const |
| 68 |
{ |
| 69 |
for (unsigned ix = sizeof (buffer)/ sizeof (buffer[0]); ix--;) |
| 70 |
if (buffer[ix].c) |
| 71 |
return false; |
| 72 |
return true; |
| 73 |
} |
| 74 |
|
| 75 |
void *operator new (__SIZE_TYPE__ size, void *p) |
| 76 |
{ |
| 77 |
return p; |
| 78 |
} |
| 79 |
|
| 80 |
char heap[5000000]; |
| 81 |
|
| 82 |
int main () |
| 83 |
{ |
| 84 |
for (unsigned ix = sizeof (heap); ix--;) |
| 85 |
heap[ix] = ix; |
| 86 |
|
| 87 |
try |
| 88 |
{ |
| 89 |
foo *f = new (heap) foo (); |
| 90 |
return 1; |
| 91 |
} |
| 92 |
catch (...) |
| 93 |
{ |
| 94 |
if (elt::count) |
| 95 |
return 2; |
| 96 |
if (elt::abort) |
| 97 |
return elt::abort + 3; |
| 98 |
} |
| 99 |
|
| 100 |
for (unsigned ix = sizeof (heap); ix--;) |
| 101 |
heap[ix] = ix; |
| 102 |
|
| 103 |
elt::count = -1; |
| 104 |
foo *f = new (heap) foo (); |
| 105 |
if (!f->check ()) |
| 106 |
return 3; |
| 107 |
return 0; |
| 108 |
} |
| 109 |
|
| 110 |
|