1 /*
2  * Bug found by Derrick Bass <derrick@tapir.caltech.edu>.  In
3  * ../blitz/arrayeval.cc, evaluateWithStackTraversal1(), there
4  * was an error in unrolling loops with common strides which caused
5  * the wrong loop bounds to be chosen.  As a result, more elements
6  * were overwritten than were supposed to be.  The appropriate
7  * fix was changing this line:
8  *
9  *             int n1 = (ubound & 3) * commonStride;
10  *
11  * to
12  *
13  *             int n1 = (length(firstRank) & 3) * commonStride;
14  *
15  * -- TV 980402
16  */
17 
18 #include "testsuite.h"
19 
20 #include <blitz/tuning.h>
21 
22 #define BZ_ARRAY_STACK_TRAVERSAL_UNROLL
23 #define BZ_ARRAY_EXPR_USE_COMMON_STRIDE
24 
25 #include <blitz/array.h>
26 
27 using namespace std;
28 using namespace blitz;
29 
30 int assignCount = 0;
31 
32 class ddouble {
33   double d;
34 
35 public:
ddouble()36   ddouble() : d(0) { }
ddouble(double _d)37   ddouble(double _d) : d(_d) { }
38 
operator =(double _d)39   ddouble& operator=(double _d) {
40     d = _d;
41     return *this; }
operator =(ddouble _d)42   ddouble& operator=(ddouble _d) {
43     d = _d.d;
44     ++assignCount;
45     return *this; }
46 
operator double()47   operator double() { return d; }
48 };
49 
main()50 int main()
51 {
52   Range fr(0,11);
53   Range bw2(0,2);
54 
55   Array<ddouble, 2> D(bw2,fr);
56 
57   D(bw2, 11) = 0;
58 
59   BZTEST(assignCount == 3);
60   return 0;
61 }
62 
63