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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.old-deja/] [g++.abi/] [arraynew.C] - Blame information for rev 699

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 699 jeremybenn
// { dg-do run  }
2
// Origin: Mark Mitchell 
3
// Avoid use of none-overridable new/delete operators in shared
4
// { dg-options "-static" { target *-*-mingw* } }
5
 
6
#if defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100
7
 
8
#include 
9
#include 
10
 
11
void* p;
12
 
13
void* operator new[](size_t s)
14
#if __cplusplus <= 199711L
15
  throw (std::bad_alloc)
16
#endif
17
{
18
  // Record the base of the last array allocated.
19
  p = malloc (s);
20
  return p;
21
}
22
 
23
template 
24
void check_no_cookie (int i)
25
{
26
  void* a = new T[7];
27
  if (p != a)
28
    exit (i);
29
}
30
 
31
template 
32
void check_no_placement_cookie (int i)
33
{
34
  p = malloc (13 * sizeof (T));
35
  void* a = new (p) T[13];
36
  if (p != a)
37
    exit (i);
38
}
39
 
40
template 
41
void check_cookie (int i)
42
{
43
  void* a = new T[11];
44
  size_t x;
45
 
46
  // Compute the cookie location manually.
47
#ifdef __ARM_EABI__
48
  x = 8;
49
#else
50
  x = __alignof__ (T);
51
  if (x < sizeof (size_t))
52
    x = sizeof (size_t);
53
#endif
54
  if ((char *) a - x != (char *) p)
55
    exit (i);
56
 
57
  // Check the cookie value.
58
  size_t *sp = ((size_t *) a) - 1;
59
  if (*sp != 11)
60
    exit (i);
61
 
62
#ifdef __ARM_EABI__
63
  sp = ((size_t *) a) - 2;
64
  if (*sp != sizeof (T))
65
    exit (i);
66
#endif
67
}
68
 
69
template 
70
void check_placement_cookie (int i)
71
{
72
  p = malloc (sizeof (T) * 11 + 100);
73
  void* a = new (p) T[11];
74
  size_t x;
75
 
76
  // Compute the cookie location manually.
77
#ifdef __ARM_EABI__
78
  x = 8;
79
#else
80
  x = __alignof__ (T);
81
  if (x < sizeof (size_t))
82
    x = sizeof (size_t);
83
#endif
84
  if ((char *) a - x != (char *) p)
85
    exit (i);
86
 
87
  // Check the cookie value.
88
  size_t *sp = ((size_t *) a) - 1;
89
  if (*sp != 11)
90
    exit (i);
91
 
92
#ifdef __ARM_EABI__
93
  sp = ((size_t *) a) - 2;
94
  if (*sp != sizeof (T))
95
    exit (i);
96
#endif
97
}
98
 
99
struct X {};
100
 
101
template 
102
struct Y { int i; virtual void f () {} };
103
 
104
// A class with a non-trivial destructor -- it needs a cookie.
105
struct Z { ~Z () {} };
106
// Likewise, but this class needs a bigger cookie so that the array
107
// elements are correctly aligned.
108
struct Z2 { ~Z2 () {} long double d; };
109
 
110
struct W1 { void operator delete[] (void *, size_t) {} };
111
struct W2 { void operator delete[] (void *) {}
112
            void operator delete[] (void *, size_t) {} };
113
struct W3 { void operator delete[] (void *, size_t) {}
114
            void operator delete[] (void *) {} };
115
struct W4 : public W1 {};
116
 
117
struct V { void *operator new[] (size_t s, void *p)
118
             { return p; }
119
           ~V () {}
120
         };
121
 
122
int main ()
123
{
124
  // There should be no cookies for types with trivial destructors.
125
  check_no_cookie (1);
126
  check_no_cookie (2);
127
  check_no_cookie > (3);
128
 
129
  // There should be no cookies for allocations using global placement
130
  // new.
131
  check_no_placement_cookie (4);
132
  check_no_placement_cookie (5);
133
  check_no_placement_cookie (6);
134
 
135
  // There should be a cookie when using a non-trivial destructor.
136
  check_cookie (7);
137
  check_cookie (8);
138
 
139
  // There should be a cookie when using the two-argument array delete
140
  // operator.
141
  check_cookie (9);
142
  check_cookie (10);
143
  // But not when the one-argument version is also available.
144
  check_no_cookie (11);
145
  check_no_cookie (12);
146
 
147
  // There should be a cookie when using a non-global placement new.
148
  check_placement_cookie (13);
149
}
150
 
151
#else /* !(defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100) */
152
 
153
int main ()
154
{
155
}
156
 
157
#endif /* !(defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100) */

powered by: WebSVN 2.1.0

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