diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/g++.dg/init/new19.C | |
download | cbb-gcc-4.6.4-15d2061ac0796199866debe9ac87130894b0cdd3.tar.bz2 cbb-gcc-4.6.4-15d2061ac0796199866debe9ac87130894b0cdd3.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/init/new19.C')
-rw-r--r-- | gcc/testsuite/g++.dg/init/new19.C | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/init/new19.C b/gcc/testsuite/g++.dg/init/new19.C new file mode 100644 index 000000000..a25be7da7 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/new19.C @@ -0,0 +1,73 @@ +// { dg-do compile } +// { dg-options "-O2 -fstrict-aliasing -fdump-tree-pre-details" } + +// Make sure we hoist invariants out of the loop even in the presence +// of placement new. This is similar to code in tramp3d. + +typedef __SIZE_TYPE__ size_t; + +inline void* operator new(size_t, void* __p) throw() { return __p; } + +template <class T, int D> +class Vector +{ +public: + Vector() + { + for (int i = 0; i < D; ++i) + new (&x_m[i]) T(); + } + T& operator[](int i) { return x_m[i]; } + +private: + T x_m[D]; +}; + +struct sia +{ + int ai[3]; +}; + +struct s +{ + struct si + { + sia* p; + } asi[3]; + float* pd; +}; + +class c +{ + int foo(int, int, int); + s sm; +}; + + +extern void bar(Vector<float, 3>*, int); +int c::foo(int f1, int f2, int f3) +{ + float sum = 0; + for (int i = 0; i < 3; ++i) + { + for (int j = 0; j < 3; ++j) + { + Vector<float, 3> v; + v[0] = 1.0; + v[1] = 2.0; + v[2] = 3.0; + for (int k = 0; k < 3; ++k) + { + float f = (f1 * this->sm.asi[0].p->ai[0] + + f2 * this->sm.asi[1].p->ai[0] + + f3 * this->sm.asi[2].p->ai[0]); + sum += f * v[k]; + } + *this->sm.pd = sum; + } + } + return sum; +} + +// { dg-final { scan-tree-dump "Replaced.*->ai\\\[0\\\]" "pre" } } +// { dg-final { cleanup-tree-dump "pre" } } |