summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/tree-ssa/pr16688.C
blob: ce88bc2b2dc9cb1526f99b31a4d1d584330273f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/* PR 16688.  Test provided by Wolfgang Bangerth.  The alias analyzer
   was aborting when trying to group aliases.  */

/* { dg-do compile } */
/* { dg-options "-O2" } */

template<typename _Tp>
struct iterator_traits;

template<typename _Tp>
struct iterator_traits<_Tp*> {
    typedef _Tp& reference;
};

template<typename _Iterator> struct NI {
    _Iterator current;

    typedef typename iterator_traits<_Iterator>::reference reference;

    NI() { }

    NI(const _Iterator& __i) : current(__i) { }

    reference operator*() const { return *current; }

    NI& operator++() { return *this; }

    const _Iterator& base() const { return current; }
};

template<typename _IteratorL, typename _IteratorR>
inline int
operator-(const NI<_IteratorL>& __lhs,
          const NI<_IteratorR>& __rhs)
{ return __lhs.base() - __rhs.base(); }


template<typename _II, typename _OI>
inline _OI
__copy_aux(_II __first, _II __last, _OI __result)
{
  struct __copy {
      static _OI
      copy(_II __first, _II __last, _OI __result)
        {
          for (; __first != __last; ++__result, ++__first)
            *__result = *__first;
          return __result;
        }
  };

  return __copy::copy(__first, __last, __result);
}

struct __copy_normal
{
    template<typename _II, typename _OI>
    static _OI
    copy_n(_II __first, _II __last, _OI __result)
      {
        return __copy_aux(__first, __last, __result);
      }
};
template<typename _InputIterator, typename _OutputIterator>
inline _OutputIterator
copy(_InputIterator __first, _InputIterator __last,
     _OutputIterator __result)
{
  return __copy_normal::copy_n(__first, __last, __result);
}

template <typename T, typename U, typename V>
void uninitialized_fill_n(T,U,V);


template<typename _Tp>
struct _Vector_base {
    struct _Vector_impl {
        _Tp* start;
        _Tp* finish;
        _Tp* end_of_storage;
        _Vector_impl() : start(0), finish(0), end_of_storage(0)
          { }
    } impl;

    _Vector_base(unsigned __n) {
      impl.start = allocate(__n);
      impl.finish = impl.start;
      impl.end_of_storage = impl.start + __n;
    }

    ~_Vector_base() {
      deallocate(impl.start,
                    impl.end_of_storage - impl.start);
    }

    _Tp* allocate(unsigned __n);

    void deallocate(_Tp* __p, unsigned __n);

    NI<_Tp*> begin() { return NI<_Tp*> (impl.start); }
};


template<typename _Tp>
struct vector : _Vector_base<_Tp>
{
    vector(int __n)
                    : _Vector_base<_Tp>(__n)
      {
        uninitialized_fill_n(this->impl.start, __n, _Tp());
      }
};



struct Tensor
{
    Tensor ();
    Tensor (const Tensor &);

    double values[2];
};


inline
Tensor::Tensor (const Tensor &p)
{
  for (unsigned int i=0; i<2; ++i)
    values[i] = p.values[i];
}


struct TriaAccessor
{
    typedef void * AccessorData;

    void copy_from (const TriaAccessor &);
    void operator = (const TriaAccessor *);

    TriaAccessor & operator = (const TriaAccessor &);

    bool operator == (const TriaAccessor &) const;

    bool operator != (const TriaAccessor &) const;
    void operator ++ ();

    int state () const;
    bool used () const;

    int present_level;
    int present_index;
    int** levels;
};

inline int TriaAccessor::state () const {
  if ((present_level>=0) && (present_index>=0))
    return 0;
  else
    if ((present_level==-1) && (present_index==-1))
      return 1;
    else
      return 2;
}


inline
void TriaAccessor::operator ++ () {
  ++this->present_index;

  while (this->present_index >=
         static_cast<int>(*this->levels[this->present_level]))
    {
      ++this->present_level;
      this->present_index = 0;

      if (this->present_level >= static_cast<int>(1))
        {

          this->present_level = this->present_index = -1;
          return;
        }
    }
}

struct MGDoFObjectAccessor : TriaAccessor {};



struct TriaRawIterator
{
    TriaRawIterator ();

    TriaRawIterator (const TriaRawIterator &);
    TriaRawIterator (const MGDoFObjectAccessor &a);
    const MGDoFObjectAccessor & operator * () const;
    
    MGDoFObjectAccessor & operator * ();
    const MGDoFObjectAccessor * operator -> () const;

    MGDoFObjectAccessor * operator -> ();

    TriaRawIterator & operator = (const TriaRawIterator &);

    bool operator == (const TriaRawIterator &) const;
    bool operator != (const TriaRawIterator &) const;
    bool operator < (const TriaRawIterator &) const;
    MGDoFObjectAccessor accessor;

    TriaRawIterator & operator ++ ();
};

struct TriaIterator : TriaRawIterator
{
    TriaIterator ();

    TriaIterator (const TriaIterator &i);

    TriaIterator &
    operator = (const TriaIterator &);

    TriaIterator &
    operator = (const TriaRawIterator &);
};


inline
TriaRawIterator::TriaRawIterator (const TriaRawIterator &i) :
                accessor (i.accessor) {}

inline
TriaIterator::TriaIterator (const TriaIterator &i) :
                TriaRawIterator (static_cast<TriaRawIterator >(i)) {}

inline
TriaRawIterator & TriaRawIterator::operator ++ () {
  while (++accessor, (this->accessor.state() == 0))
    if (this->accessor.used() == true)
      return *this;
  return *this;
}

struct Comp {
    Comp (const Tensor &dir) : dir(dir) {}

    bool operator () (const TriaIterator &c1, const TriaIterator &c2) const;
    const Tensor dir;
};


template<typename Iter>
void x1(Iter first, Iter last, int i, Comp comp)
{
  x1(Iter(), last, i, comp);
}

template<typename Iter>
inline void x2(Iter first, Iter last, Comp comp)
{
  if (first.base() != last.base())
    x1(first, last, (last - first), comp);
}

void downstream_dg (const Tensor& direction)
{
  vector<TriaIterator> ordered_cells(13);
  const Comp comparator(direction);

  TriaIterator begin, end;

  copy (begin, end, ordered_cells.begin());
  x2 (ordered_cells.begin(), ordered_cells.begin(), comparator);
}