Community
cancel
Showing results for
Search instead for
Did you mean:
Beginner
98 Views

## Weird icpc compiler bug??

This is a section of code that's supposed to calculate the number of monomial terms necessary to represent a polynomial in x and y, where the polynomial order along x and y can be different. This is about as pared down as I could get it and still recreate the bug.

```[cpp]#include

// note defining MAX as a macro (as opposed to
// a function) is necessary in order to recreate
// the bug
#define MAX(X,Y) (((X) > (Y)) ? (X) : (Y))

using namespace std;

int main(int argc, char **argv){

int N=1;

int *xOrder=new int; //note: xOrder and yOrder must be
int *yOrder=new int; // be arrays in order to recreate the bug

for (int i=0;i=1;
yOrder=1;
}

for (int i=0;i,yOrder);
for (int o=0;o<=order;o++){
for (int ii=0;ii<=o;ii++){
int oX=ii;int oY=o-ii;
if (oX>xOrder || oY>yOrder)
continue;
if ((oX+oY)>MAX(xOrder,yOrder))
continue;
// note: no comments can be in this section if we want to recreate
//   the bug
//cout << i << " " << cnt << " x^" << oX << " y^" << oY << endl;
cnt++;
}
}

// if xOrder==yOrder==1, cnt should equal 3
cout <<  " cnt=" << cnt << endl;
}

delete [] xOrder;
delete [] yOrder;

return 0;
}
[/cpp]```

When compiling this code with icpc and the compiler flags -O0 or -O1, I get the correct output (cnt=3), whereas if I compile with -O2 or -O3, I get a wrong answer (cnt=2).
```[bash]icpc -o bug_test_rel -O3 intel_bug_test.cc
icpc -o bug_test_dbg -g -O0 intel_bug_test.cc[/bash]```

I worked around this issue by defining MAX() as a function instead of a macro, but I'm posting this because I'm not really sure why this happened. If I did something wrong here, I don't see it.

I'm running this on CentOS 5.5, and "icpc --version" yields

```[bash]icpc (ICC) 11.1 20090827
Copyright (C) 1985-2009 Intel Corporation.  All rights reserved.

[/bash]```
3 Replies
Employee
98 Views
I get the correct answer. I am using FC11 and icc 11.1.072.
Black Belt
98 Views
There were bugs in the scoping of new[] and the like in those versions. Note that the good versions of 11.1 were issued over a year later than the one quoted.
Beginner
98 Views
I'm running 11.1.056. I didn't realize this wasn't a "good version". I'll make sure to upgrade to the current version.

Thanks