1 // { dg-do run }
2 
3 typedef __PTRDIFF_TYPE__ ptrdiff_t;
4 
5 template <typename T>
6 class I
7 {
8 public:
9   typedef ptrdiff_t difference_type;
10   I ();
11   ~I ();
12   I (T *);
13   I (const I &);
14   T &operator * ();
15   T *operator -> ();
16   T &operator [] (const difference_type &) const;
17   I &operator = (const I &);
18   I &operator ++ ();
19   I operator ++ (int);
20   I &operator -- ();
21   I operator -- (int);
22   I &operator += (const difference_type &);
23   I &operator -= (const difference_type &);
24   I operator + (const difference_type &) const;
25   I operator - (const difference_type &) const;
26   template <typename S> friend bool operator == (I<S> &, I<S> &);
27   template <typename S> friend bool operator == (const I<S> &, const I<S> &);
28   template <typename S> friend bool operator < (I<S> &, I<S> &);
29   template <typename S> friend bool operator < (const I<S> &, const I<S> &);
30   template <typename S> friend bool operator <= (I<S> &, I<S> &);
31   template <typename S> friend bool operator <= (const I<S> &, const I<S> &);
32   template <typename S> friend bool operator > (I<S> &, I<S> &);
33   template <typename S> friend bool operator > (const I<S> &, const I<S> &);
34   template <typename S> friend bool operator >= (I<S> &, I<S> &);
35   template <typename S> friend bool operator >= (const I<S> &, const I<S> &);
36   template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &);
37   template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &);
38   template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &);
39 private:
40   T *p;
41 };
I()42 template <typename T> I<T>::I () : p (0) {}
~I()43 template <typename T> I<T>::~I () {}
I(T * x)44 template <typename T> I<T>::I (T *x) : p (x) {}
I(const I & x)45 template <typename T> I<T>::I (const I &x) : p (x.p) {}
46 template <typename T> T &I<T>::operator * () { return *p; }
47 template <typename T> T *I<T>::operator -> () { return p; }
48 template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; }
49 template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; }
50 template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; }
51 template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); }
52 template <typename T> I<T> &I<T>::operator -- () { --p; return *this; }
53 template <typename T> I<T> I<T>::operator -- (int) { return I (p--); }
54 template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; }
55 template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; }
56 template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); }
57 template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); }
58 template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; }
59 template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; }
60 template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); }
61 template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); }
62 template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; }
63 template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; }
64 template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; }
65 template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; }
66 template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; }
67 template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; }
68 template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; }
69 template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; }
70 template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; }
71 template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; }
72 template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); }
73 
RR74 struct R { R () {}; ~R () {}; I<int> r; };
TT75 struct T { T () {}; virtual ~T () {}; I<int> t; };
AA76 struct A : public R, virtual public T { A () {} I<int> a; void m1 (const I<int> &, const I<int> &); };
77 template <typename Q>
UU78 struct U { U () {}; virtual ~U () {}; Q t; };
79 template <typename Q>
BB80 struct B : public R, virtual public U<Q> { B () {} Q a; void m2 (const Q &, const Q &, const I<int> &, const I<int> &); };
81 
82 int d[64];
83 
84 void
m1(const I<int> & x,const I<int> & y)85 A::m1 (const I<int> &x, const I<int> &y)
86 {
87   int w = 0;
88   #pragma omp parallel for private (a) reduction(|:w)
89   for (a = x; A::a < y - 33; a += 2)
90     w |= (1 << *A::a);
91   if (w != 0x55555555)
92     __builtin_abort ();
93   #pragma omp parallel for lastprivate (t)
94   for (T::t = x; t < y - 32; t += 3)
95     d[*T::t + 2] |= 1;
96   if (*T::t != 33)
97     __builtin_abort ();
98   for (int i = 0; i < 64; i++)
99     if (d[i] != ((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 1 : 0))
100       __builtin_abort ();
101   w = 0;
102   #pragma omp parallel for reduction(|:w)
103   for (a = x; A::a < y - 33; a += 2)
104     w |= (1 << *A::a);
105   if (w != 0x55555555)
106     __builtin_abort ();
107   #pragma omp taskloop
108   for (R::r = x; r < y - 32; R::r += 2)
109     d[*r + 8] |= 2;
110   for (int i = 0; i < 64; i++)
111     if (d[i] != (((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 1 : 0)
112 		 | ((i >= 8 && i < 32 + 8 && (i & 1) == 0) ? 2 : 0)))
113       __builtin_abort ();
114   #pragma omp taskloop collapse(2)
115   for (T::t = x; t < y - 57; t += 2)
116     for (a = x; A::a < y - 56; a++)
117       d[((*t << 2) | *a) + 3] |= 4;
118   for (int i = 0; i < 64; i++)
119     if (d[i] != (((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 1 : 0)
120 		 | ((i >= 8 && i < 32 + 8 && (i & 1) == 0) ? 2 : 0)
121 		 | ((i >= 3 && i < 32 + 3) ? 4 : 0)))
122       __builtin_abort ();
123 }
124 
125 template <typename Q>
126 void
m2(const Q & u,const Q & v,const I<int> & x,const I<int> & y)127 B<Q>::m2 (const Q &u, const Q &v, const I<int> &x, const I<int> &y)
128 {
129   int w = 0;
130   #pragma omp parallel for private (a) reduction(|:w)
131   for (a = u; B::a < v - 33; a += 2)
132     w |= (1 << *B::a);
133   if (w != 0x55555555)
134     __builtin_abort ();
135   #pragma omp parallel for lastprivate (U<Q>::t)
136   for (U<Q>::t = u; U<Q>::t < v - 32; U<Q>::t += 3)
137     d[*U<Q>::t + 2] |= 1;
138   if (*U<Q>::t != 33)
139     __builtin_abort ();
140   for (int i = 0; i < 64; i++)
141     if (d[i] != ((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 1 : 0))
142       __builtin_abort ();
143   w = 0;
144   #pragma omp parallel for reduction(|:w)
145   for (a = u; B::a < v - 33; a += 2)
146     w |= (1 << *B::a);
147   if (w != 0x55555555)
148     __builtin_abort ();
149   #pragma omp taskloop
150   for (R::r = x; r < y - 32; R::r += 2)
151     d[*r + 8] |= 2;
152   for (int i = 0; i < 64; i++)
153     if (d[i] != (((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 1 : 0)
154 		 | ((i >= 8 && i < 32 + 8 && (i & 1) == 0) ? 2 : 0)))
155       __builtin_abort ();
156   #pragma omp taskloop collapse(2)
157   for (U<Q>::t = u; U<Q>::t < v - 57; U<Q>::t += 2)
158     for (a = u; B::a < v - 56; a++)
159       d[((*U<Q>::t << 2) | *a) + 3] |= 4;
160   for (int i = 0; i < 64; i++)
161     if (d[i] != (((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 1 : 0)
162 		 | ((i >= 8 && i < 32 + 8 && (i & 1) == 0) ? 2 : 0)
163 		 | ((i >= 3 && i < 32 + 3) ? 4 : 0)))
164       __builtin_abort ();
165 }
166 
167 int
main()168 main ()
169 {
170   A a;
171   int b[128];
172   for (int i = 0; i < 128; i++)
173     b[i] = i - 32;
174   a.m1 (&b[32], &b[96]);
175   for (int i = 0; i < 64; i++)
176     d[i] = 0;
177   B<I<int> > c;
178   c.m2 (&b[32], &b[96], &b[32], &b[96]);
179   for (int i = 0; i < 64; i++)
180     d[i] = 0;
181   B<int *> d;
182   d.m2 (&b[32], &b[96], &b[32], &b[96]);
183 }
184