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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 693 jeremybenn
// PR middle-end/6247
2
// This testcase was miscompiled on IA-32 because a single stack slot
3
// was used for 2 different variables at the same time.
4
// The function H::h1 was miscompiled.
5
// { dg-do run }
6
// { dg-options "-O2" }
7
 
8
extern "C" void abort (void);
9
extern "C" void exit (int);
10
 
11
struct A
12
{
13
  A () { a = 1; }
14
  void a1 () { a++; }
15
  bool a2 () { return !--a; }
16
  unsigned int a;
17
};
18
 
19
struct B : public A
20
{
21
  B () : b (0) { a1 (); }
22
  void b1 ();
23
  const char *b;
24
};
25
 
26
struct C
27
{
28
  C ();
29
  C (const C &);
30
  ~C () { if (c->a2 ()) { if (c == c0) c0 = 0; c->b1 (); } }
31
  C &operator= (const C &);
32
  static C c1 (const char *x, int y = -1);
33
  C (int, bool);
34
  void a2 ();
35
  B *c;
36
  static B *c0;
37
};
38
 
39
B *C::c0 = __null;
40
 
41
template  struct D
42
{
43
  D (const T& t) : d (t) {}
44
  D () {}
45
  D *next, *prev;
46
  T d;
47
};
48
 
49
template struct E
50
{
51
  D *e;
52
  E () : e (0) {}
53
  E (D *p) : e (p) {}
54
  E (const E& x) : e (x.e) {}
55
  const T& operator* () const { return e->d; }
56
  T& operator* () { return e->d; }
57
  bool operator== (const E& x) const { return e == x.e; }
58
  bool operator!= (const E& x) const { return e != x.e; }
59
  E operator++ (int) { E x = *this; e = e->next; return x; }
60
};
61
 
62
template  struct F : public A
63
{
64
  F () { f = new D; f->next = f->prev = f; f0 = 0; }
65
  ~F () {}
66
  D *f;
67
  unsigned int f0;
68
 
69
  F (const F& x) : A ()
70
  {
71
    f = new D; f->next = f->prev = f; f0 = 0;
72
    E b (x.f->next);
73
    E e (x.f);
74
    E i (f);
75
    while (b != e)
76
      f1 (i, *b++);
77
  }
78
 
79
  E f1 (E x, const T& y)
80
  {
81
    D *p = new D (y);
82
    p->next = x.e;
83
    p->prev = x.e->prev;
84
    x.e->prev->next = p;
85
    x.e->prev = p;
86
    f0++;
87
    return p;
88
  }
89
};
90
 
91
template  struct G
92
{
93
  E g1 () { g3 (); return E (g->f); }
94
  E g2 (const T& x) { g3 (); return g->f1 (g1 (), x); }
95
  void g3 () { if (g->a > 1) { g->a2 (); g = new F (*g); } }
96
  F* g;
97
};
98
 
99
struct H
100
{
101
  virtual ~H () {};
102
  virtual void h1 ();
103
  struct I
104
  {
105
    I () {}
106
    I (C r, C p) : i1 (r), i2 (p) {}
107
    C i1, i2;
108
  };
109
  G h;
110
};
111
 
112
void H::h1 ()
113
{
114
  h.g2 (I (C::c1 ("s1"), C::c1 ("t")));
115
  h.g2 (I (C::c1 ("s2"), C::c1 ("t")));
116
  h.g2 (I (C::c1 ("s3"), C::c1 ("t")));
117
}
118
 
119
void B::b1 ()
120
{
121
}
122
 
123
C C::c1 (const char *x, int y)
124
{
125
  C z;
126
 
127
  if (y != -1)
128
    abort ();
129
  z.c = new B;
130
  z.c->b = x;
131
  return z;
132
}
133
 
134
C::C () : c (__null)
135
{
136
}
137
 
138
C::C (const C &x)
139
{
140
  c = x.c;
141
  c->a1 ();
142
}
143
 
144
int main ()
145
{
146
  H h;
147
  h.h.g = new F ();
148
  h.h1 ();
149
  if (h.h.g->f0 != 3)
150
    abort ();
151
  D *p;
152
  int i;
153
  for (i = 0, p = h.h.g->f; i < 4; i++, p = p->next)
154
    {
155
      if (i == 0 && (p->d.i1.c != __null || p->d.i2.c != __null))
156
        abort ();
157
      if (i > 0
158
          && (p->d.i1.c->b[0] != 's'
159
              || p->d.i1.c->b[1] != '0' + i
160
              || p->d.i1.c->b[2] != '\0'
161
              || __builtin_strcmp (p->d.i2.c->b, "t")))
162
        abort ();
163
      if (p->prev->next != p)
164
        abort ();
165
      if (p->next->prev != p)
166
        abort ();
167
      if (i == 3 && p->next != h.h.g->f)
168
        abort ();
169
    }
170
  exit (0);
171
}

powered by: WebSVN 2.1.0

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