Is this a bug in intel C++ compiler?

Is this a bug in intel C++ compiler?

I am using intel c++ compiler 12.0, and working on a program similar to the following, which is very simple and straightforward. The while loop should stop in the first run. However, when I build the code using /O2 flag with the intel compiler, the while loop never stops. If I disable the optimization, or use visual c++, the loop exits normally. If I change pt->flag to p.flag, which I suppose is the same thing, the loop exits normally too. I think it has something to do with intel's optimization. Is this a bug in the intel compiler? or I missed something here?

#include <iostream>

using namespace std;

struct para {
  int i;
  int flag;
};

int main(int argc, char **argv)
{
  para p;
  p.i = 0;
  p.flag = 1;

  para * pt = &p;
  cout << "loop started" << endl;

  int i;
  while (p.flag) {
    if (p.i == 0) {
      for (i=0; i<1; i++) {
        if (p.flag != 1)
          break;
      }
      if (i==1) {
        pt->flag = 0;
      }
    }
  }
  cout << "loop stopped" << endl;
  return 1;
}

4 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

Hi Dan,

I can reproduce your issue. And also, it can work if you change "while (p.flag)" to "while(pt->flag)". This is a compiler bug and it is caused by the "dead code elimination" optimization. I will submit the test case to the developer team to fix.

Thanks,
Shenghong

Hi Dan,
could you please upgrade to latest icc 12.1 (update 11) compiler? I found it can work with 12.1 compiler. I was reproducing your issue with 13.0 beta and the issue can be reproduced also. So this seems to be a regression bug.
Thanks,
Shenghong

Hi Dan,

This issue is fixed in update 3 (and 2). Could you please upgrade to latest version to have a try. Let me know if you can reproduce the issue still.

#source /opt/intel/composer_xe_2013.1.117/bin/compilervars.sh intel64
#icc temp.cpp && ./a.out
loop started
^C
#source /opt/intel/composer_xe_2013.3.163/bin/compilervars.sh intel64
#icc temp.cpp && ./a.out
loop started
loop stopped
#

Thanks,

Shenghong

Melden Sie sich an, um einen Kommentar zu hinterlassen.