blob: cd5944d2439984502b57c8d7b4c29e983e8bea63 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
// PR tree-optimization/27549
// { dg-do compile }
// { dg-options "-O2" }
typedef __SIZE_TYPE__ size_t;
struct E
{
virtual ~E () {}
virtual size_t e () const = 0;
virtual void f (char *x) const = 0;
};
struct F : public E
{
F () {}
virtual ~F () {}
virtual size_t e () const { return 0; }
virtual void f (char *x) const { *x = '\0'; }
};
struct S
{
S () { a = new char[32]; b = 32; c = 0; a[0] = 0; }
void s (const char *x, size_t y) { v (c + y + 1); __builtin_memcpy(a + c, x, y); c += y; a[c] = '\0'; }
void s (const E *x) { size_t l = x->e(); v (c + l + 1); x->f (a + c); c += l; }
const char *t () { return a; }
void v (size_t n)
{
if (b >= n) return;
size_t b2 = b;
char *a2 = a;
for (;;)
{
b *= 2;
if (b >= n)
break;
}
a = new char[b];
if (b2)
{
__builtin_memcpy(a, a2, c);
a2[0] = 0;
for (size_t i = 1; i < b2; i++)
a2[i] = a2[i - 1];
delete[] a2;
}
}
~S ()
{
if (b)
{
a[0] = 0;
for (size_t i = 1; i < b; i++)
a[i] = a[i - 1];
}
delete[] a;
}
char * a;
size_t b, c;
};
const char *p;
size_t q;
const F u;
const char *
foo ()
{
S s;
s.s (p, q);
s.s (&u);
return s.t ();
}
|