OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.dg/] [init/] [array16.C] - Blame information for rev 693

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.