Debian Codegraph @

gcc/testsuite/g++.dg/opt/temp2.C

raw
1 // { dg-do run }
2 // { dg-require-effective-target size20plus }
3
4 // Copyright (C) 2006 Free Software Foundation, Inc.
5
6 // Originally from PR 16681, found also in init/array15.C
7 // This variant of the testcase verifies that we do not create
8 // a temporary on the stack, which is PR 27620.
9
10 int i;
11
12 extern "C"
13 void *memcpy (void *dest, const void *src, __SIZE_TYPE__ n)
14 {
15 char *d = (char *) dest;
16 const char *s = (const char *) src;
17 while (n--)
18 d[n] = s[n];
19 ++i;
20 return dest;
21 }
22
23 struct foo {
24 unsigned char buffer[41112];
25 foo() ;
26 bool check () const;
27 };
28
29 foo::foo ()
30 : buffer()
31 {}
32
33 bool foo::check () const
34 {
35 for (unsigned ix = sizeof (buffer); ix--;)
36 if (buffer[ix])
37 return false;
38 return true;
39 }
40
41 void *operator new (__SIZE_TYPE__ size, void *p)
42 {
43 return p;
44 }
45
46 char heap[50000];
47
48 int main ()
49 {
50 for (unsigned ix = sizeof (heap); ix--;)
51 heap[ix] = ix;
52
53 i = 0;
54 foo *f = new (heap) foo ();
55
56 if (i != 0)
57 return 1;
58 if (!f->check ())
59 return 1;
60 return 0;
61 }
62
63