1 // PR optimization/11198
2 // Origin: Joerg Walter <jhr.walter@t-online.de>
3 // Reduced testcase by: Volker Reichelt <reichelt@igpm.rwth-aachen.de>
4 // Wolfgang Bangerth <bangerth@ticam.utexas.edu>
6 // The compiler used to allocate the same stack slot for two aggregates,
7 // overlooking that assignments to members given the same address on the
8 // stack may not alias and thus may be reordered by the scheduling passes.
11 // { dg-options "-O2 -frename-registers" }
17 min(const int& a, const int& b) {
18 if (b < a) return b; return a;
21 struct barrier { barrier () {} };
23 template <typename=void> struct unbounded_array {
24 inline unbounded_array (): data_ (new double [9]) {}
25 inline double& operator [] (int i) { return data_ [i]; }
29 inline int element (int i, int j) {
33 template <typename=void>
35 inline matrix () : size2_ (3) {}
37 inline unbounded_array<> &data () { return data_; }
39 inline double& el (int i, int j) {
41 int dead2 = 1 + i - j;
42 if (j < size2_ && i-j < 2)
43 return data () [element (j,i-j+1)];
50 inline iterator2 find () {
51 return iterator2 (*this);
55 inline iterator1 (matrix *m):
63 unbounded_array<> data_;
67 template<typename=void>
69 adaptor (matrix<> &m) : m(&m), upper_ (1) {}
72 int size2 () const { return 3; }
73 int lower () const { return 1; }
74 int upper () const { return upper_; }
75 matrix<> &data () { return *m; }
77 double& el (int i, int j) {
79 if (j < size2 () && i-j < 1)
80 return data ().el (i, j);
89 a_iterator1 (adaptor &a, const matrix<>::iterator1 &it1):
90 a (&a), dead1 (it1) {}
92 a_iterator2 begin () const {
93 return a_iterator2(*a);
96 matrix<>::iterator1 dead1;
100 a_iterator2 (adaptor &a) : a (&a) {}
104 int l = a->upper () + i;
107 l < a->lower () + 1 + a->upper ())
108 return a->m->el(0,0);
120 void matrix_swap (adaptor<> &bam1, adaptor<> &bam2)
122 adaptor<>::a_iterator1 it1 (bam1,matrix<>::iterator1(bam1.m)),
123 it2 (bam2,matrix<>::iterator1(bam2.m));
125 double x = it1.begin().f();
132 adaptor<> bam1 (m1), bam2 (m2);
133 matrix_swap (bam1, bam2);