Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

ICPC produces wrong binary !

Michael_J_8
Beginner
515 Views

The following C++ code should be complied and run under Linux.
The program should stay in the while(1) loop forever.
With g++ it does, but compiled with icpc it does not !
Probably a bug in the icc compiler ?!
Please can anyone of you try to compile the main.cpp below?
The program needs a string as argument.
$ icpc main.cpp
$ ./a.out test
-> program ends, but it should run forever !!

WHY ??

=================== CODE ==================

#include <stdio.h>
#include <iostream>
#include <string>
#include <map>using namespace std;int main(int argc, char *argv[])
{
map<string,string> m;
m["aa"] = argv[1];
while(1)
{
if (m.size() == 0)
{
cout<<"m.size():"<<m.size()<<endl;
break;
}
}
return 0;
}

0 Kudos
6 Replies
Vladimir_P_1234567890
515 Views
comment deleted --Vladimir
0 Kudos
Milind_Kulkarni__Int
New Contributor II
515 Views
Hi Michael, This looks to be a compiler issue. It looks like the compiler is doing some dead code elimination or some otimization. When you include a simple statement like cout , when you enter the while(1) loop, then it hangs as expected. like:-- while(1) { cout << "something" << endl; //simple statement if (m.size() == 0) { Since also other compilers work fine, I am escalating to our team. I will inform you about the progress. thanks
0 Kudos
levicki
Valued Contributor I
515 Views
I told them engineers not to be overzealous when it comes to optimizing infinite loops but they would not listen. I still have a case open for similar issue.
0 Kudos
levicki
Valued Contributor I
515 Views
Double post, this was not possible with old forum.
0 Kudos
Feilong_H_Intel
Employee
515 Views

I was notified that this issue has been fixed in Composer XE 2013 Update 4.  You may download it at https://registrationcenter.intel.com.  FYI.

Feilong

0 Kudos
SergeyKostrov
Valued Contributor II
515 Views
Hi Feilong, Thank you for the update. I wanted to make a note that if somebody still uses older version(s) of Intel C++ compiler a workaround is very simple and a volatile variable of any type with assignment of some value will resolve the problem. I've experienced similar issues several times especially when /O2 and /O3 compiler options are used.
0 Kudos
Reply