From: Jakub Jelinek Date: Wed, 10 Apr 2002 21:49:26 +0000 (+0200) Subject: re PR middle-end/6247 (Konqueror miscompilation on IA-32) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dab550cb99cb3dfd90de880aeea78f3d81f30048;p=gcc.git re PR middle-end/6247 (Konqueror miscompilation on IA-32) PR middle-end/6247 * g++.dg/opt/cleanup1.C: New test. * g++.dg/opt/const1.C: New test. From-SVN: r52146 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a7148b9263a..001802fc8c2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2002-04-10 Jakub Jelinek + + PR middle-end/6247 + * g++.dg/opt/cleanup1.C: New test. + + * g++.dg/opt/const1.C: New test. + 2002-04-10 Lars Brinkhoff * gcc.c-torture/execute/20020406-1.c: Declare malloc. diff --git a/gcc/testsuite/g++.dg/opt/cleanup1.C b/gcc/testsuite/g++.dg/opt/cleanup1.C new file mode 100644 index 00000000000..f34c7cf1a2d --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/cleanup1.C @@ -0,0 +1,170 @@ +// PR middle-end/6247 +// This testcase was miscompiled on IA-32 because a single stack slot +// was used for 2 different variables at the same time. +// { dg-do run } +// { dg-options "-O2" } + +extern "C" void abort (void); +extern "C" void exit (int); + +struct A +{ + A () { a = 1; } + void a1 () { a++; } + bool a2 () { return !--a; } + unsigned int a; +}; + +struct B : public A +{ + B () : b (0) { a1 (); } + void b1 (); + const char *b; +}; + +struct C +{ + C (); + C (const C &); + ~C () { if (c->a2 ()) { if (c == c0) c0 = 0; c->b1 (); } } + C &operator= (const C &); + static C c1 (const char *x, int y = -1); + C (int, bool); + void a2 (); + B *c; + static B *c0; +}; + +B *C::c0 = __null; + +template struct D +{ + D (const T& t) : d (t) {} + D () {} + D *next, *prev; + T d; +}; + +template struct E +{ + D *e; + E () : e (0) {} + E (D *p) : e (p) {} + E (const E& x) : e (x.e) {} + const T& operator* () const { return e->d; } + T& operator* () { return e->d; } + bool operator== (const E& x) const { return e == x.e; } + bool operator!= (const E& x) const { return e != x.e; } + E operator++ (int) { E x = *this; e = e->next; return x; } +}; + +template struct F : public A +{ + F () { f = new D; f->next = f->prev = f; f0 = 0; } + ~F () {} + D *f; + unsigned int f0; + + F (const F& x) : A () + { + f = new D; f->next = f->prev = f; f0 = 0; + E b (x.f->next); + E e (x.f); + E i (f); + while (b != e) + f1 (i, *b++); + } + + E f1 (E x, const T& y) + { + D *p = new D (y); + p->next = x.e; + p->prev = x.e->prev; + x.e->prev->next = p; + x.e->prev = p; + f0++; + return p; + } +}; + +template struct G +{ + E g1 () { g3 (); return E (g->f); } + E g2 (const T& x) { g3 (); return g->f1 (g1 (), x); } + void g3 () { if (g->a > 1) { g->a2 (); g = new F (*g); } } + F* g; +}; + +struct H +{ + virtual ~H () {}; + virtual void h1 (); + struct I + { + I () {} + I (C r, C p) : i1 (r), i2 (p) {} + C i1, i2; + }; + G h; +}; + +void H::h1 () +{ + h.g2 (I (C::c1 ("s1"), C::c1 ("t"))); + h.g2 (I (C::c1 ("s2"), C::c1 ("t"))); + h.g2 (I (C::c1 ("s3"), C::c1 ("t"))); +} + +void B::b1 () +{ +} + +C C::c1 (const char *x, int y) +{ + C z; + + if (y != -1) + abort (); + z.c = new B; + z.c->b = x; + return z; +} + +C::C () +{ +} + +C::C (const C &x) +{ + c = x.c; + c->a1 (); +} + +int main () +{ + H h; + h.h.g = new F (); + h.h1 (); + if (h.h.g->f0 != 3) + abort (); + D *p; + int i; + for (i = 0, p = h.h.g->f; i < 4; i++, p = p->next) + { + if (i == 0 && (p->d.i1.c != __null || p->d.i2.c != __null)) + abort (); + if (i > 0 + && (p->d.i1.c->b[0] != 's' + || p->d.i1.c->b[1] != '0' + i + || p->d.i1.c->b[2] != '\0' + || __builtin_strcmp (p->d.i2.c->b, "t"))) + abort (); + if (p->prev->next != p) + abort (); + if (p->next->prev != p) + abort (); + if (i == 3 && p->next != h.h.g->f) + abort (); + } + exit (0); +} diff --git a/gcc/testsuite/g++.dg/opt/const1.C b/gcc/testsuite/g++.dg/opt/const1.C new file mode 100644 index 00000000000..834cfd5e258 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/const1.C @@ -0,0 +1,129 @@ +// This testcase was miscompiled on IA-64 to read from unitialized memory +// and dereference it. +// { dg-do run } +// { dg-options "-O2" } + +struct A +{ + A () { a = 1; } + void a1 () { a++; } + bool a2 () { return !--a; } + unsigned int a; +}; + +struct B {}; + +template struct C +{ + C () {} + C (const T& t) : c (t) {} + C *next, *prev; + T c; +}; + +template struct D +{ + C *d; + D () : d (0) {} + D (C *x) : d (x) {} + D (const D& x) : d (x.d) {} + bool operator!= (const D& x) const { return d != x.d; } + const T& operator* () const { return d->c; } + D operator++ (int) { D t = *this; d = d->next; return t; } +}; + +template struct E +{ + C *e; + E () : e (0) {} + E (C *p) : e (p) {} + E (const E& x) : e (x.e) {} + E (const D& x) : e (x.e) {} + bool operator!= (const E& x) const { return e != x.e; } + const T& operator* () const { return e->c; } + E& operator++ () { e = e->next; return *this; } +}; + +template struct F : public A +{ + C *f; + unsigned long f0; + F () { f = new C; f->next = f->prev = f; f0 = 0; } + F (const F& x) : A () + { + f = new C; f->next = f->prev = f; f0 = 0; + D b (x.f->next), e (x.f), i (f); + while (b != e) + f1 (i, *b++); + } + + ~F () + { + C *p = f->next; + while (p != f) + { + C *x = p->next; + delete p; + p = x; + } + delete f; + } + + D f1 (D x, const T& y) + { + C *p = new C (y); + p->next = x.d; + p->prev = x.d->prev; + x.d->prev->next = p; + x.d->prev = p; + f0++; + return p; + } +}; + +template struct G +{ + F *g; + G () { g = new F; } + G (const G& x) { g = x.g; g->a1 (); } + ~G () {} + G& operator= (const G& x) { x.g->a1 (); g = x.g; return *this; } + D g1 () { g4 (); return D (g->f); } + E g1 () const { return E (g->f); } + E g2 () const { return E (g->f->next); } + D g3 (const T& x) { g4 (); return g->f1 (g1 (), x); } + void g4 () { if (g->a > 1) { g->a2 (); g = new F (*g); } } + + G operator+ (const G& x) const + { + G x2 (*this); + for (E i = x.g2 (); i != x.g1 (); ++i) + x2.g3 (*i); + return x2; + } + + G& operator+= (const G& x) + { + for (E i = x.g2 (); i != x.g1 (); ++i) + g3 (*i); + return *this; + } +}; + +struct H : public G +{ + H () {} + H (const H& x) : G (x) {} + H (const G& x) : G (x) {} +}; + +void foo (); + +int +main () +{ + H a = H () + H (); + a += H (); + H b; + b = H () + H (); +}