re PR c++/13387 (assignment to base class corrupts subclass)
authorNathan Sidwell <nathan@codesourcery.com>
Mon, 5 Jan 2004 10:15:07 +0000 (10:15 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Mon, 5 Jan 2004 10:15:07 +0000 (10:15 +0000)
PR c++/13387
* g++.dg/opt/alias3.C: New test.

Co-Authored-By: Richard Sandiford <rsandifo@redhat.com>
From-SVN: r75427

gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/alias3.C [new file with mode: 0644]

index 9b161c459b9ba4400e1f7030ce21ef10c3ce29d8..7e34508659c904ef58a42f40eeedaa35d4b7f0d2 100644 (file)
@@ -1,3 +1,9 @@
+2004-01-05  Nathan Sidwell  <nathan@codesourcery.com>
+       Richard Sandiford <rsandifo@redhat.com>
+
+       PR c++/13387
+       * g++.dg/opt/alias3.C: New test.
+
 2004-01-04  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/13157
diff --git a/gcc/testsuite/g++.dg/opt/alias3.C b/gcc/testsuite/g++.dg/opt/alias3.C
new file mode 100644 (file)
index 0000000..dc8accd
--- /dev/null
@@ -0,0 +1,45 @@
+// { dg-options "-O2" }
+
+// Contributed by Nathan Sidwell 22 Dec 2003 <nathan@codesourcery.com>
+// Origin: rsandifo@redhat.com
+
+// PR c++/13387. Alias sets were incorrect
+
+struct C {
+  C(short *p = 0, int i = 0) : ptr (p), index (i) {}
+  short operator*() { return ptr[index]; }
+  short *ptr;
+  int index;
+};
+
+C f1 (C) __attribute__ ((noinline));
+C f1 (C x)
+{
+  return x;
+}
+
+void f2 (short)__attribute__ ((noinline));;
+short s;
+
+void f2 (short s_)
+{
+  s = s_;
+}
+
+C g (C x)__attribute__ ((noinline));
+C g (C x)
+{
+  x = f1 (x); 
+  f2 (*x);
+  return x;
+}
+
+int main ()
+{
+  short p[2] = { 0x1234, 0x5678 };
+  C x (p, 1);
+
+  g (x);
+
+  return s != p[1];
+}