summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/opt/nrv11.C
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/g++.dg/opt/nrv11.C
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/g++.dg/opt/nrv11.C')
-rw-r--r--gcc/testsuite/g++.dg/opt/nrv11.C58
1 files changed, 58 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/opt/nrv11.C b/gcc/testsuite/g++.dg/opt/nrv11.C
new file mode 100644
index 000000000..2b72f790b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/nrv11.C
@@ -0,0 +1,58 @@
+// PR middle-end/25977
+// Bug: We were assuming that the return slot of the current function is
+// always safe to use as the return slot for another call, because its
+// address cannot escape. But its address can escape if we perform the
+// named return value optimization.
+
+// { dg-do run }
+
+struct A
+{
+ A( int left, int top, int width, int height )
+ : x1(left), y1(top), x2(left+width-1), y2(top+height-1) {}
+
+ //A(const A& o) : x1(o.x1), y1(o.y1), x2(o.x2), y2(o.y2) {}
+ //A& operator=(const A& o ) { x1=o.x1; y1=o.y1; x2=o.x2; y2=o.y2; return *this; }
+
+ A operator&(const A &r) const
+ {
+ A tmp(0, 0, -1, -1);
+ tmp.x1 = ((r.x1) < (x1) ? (x1) : (r.x1));
+ tmp.x2 = ((x2) < (r.x2) ? (x2) : (r.x2));
+ tmp.y1 = ((r.y1) < (y1) ? (y1) : (r.y1));
+ tmp.y2 = ((y2) < (r.y2) ? (y2) : (r.y2));
+ return tmp;
+ }
+
+ int x1;
+ int y1;
+ int x2;
+ int y2;
+};
+
+bool operator==( const A &r1, const A &r2 )
+{
+ return r1.x1==r2.x1 && r1.x2==r2.x2 && r1.y1==r2.y1 && r1.y2==r2.y2;
+}
+
+static A test()
+{
+ A all = A( 0, 0, 1024, 768);
+ A a = all;
+ A r = all;
+ a = a & r;
+ return a;
+}
+
+extern "C" void abort(void);
+
+int main( int argc, char ** argv )
+{
+ A all = A( 0, 0, 1024, 768);
+ A a = test();
+
+ if ( ! ( a == all))
+ abort();
+
+ return 0;
+}