ICPC produces wrong binary !

ICPC produces wrong binary !

Bild des Benutzers Michael J.

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;
}

7 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Bild des Benutzers Vladimir Polin (Intel)

comment deleted --Vladimir

Bild des Benutzers Milind Kulkarni (Intel)

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

Bild des Benutzers Igor Levicki

Double post, this was not possible with old forum.

-- Regards, Igor Levicki If you find my post helpfull, please rate it and/or select it as a best answer where applies. Thank you.
Bild des Benutzers Igor Levicki

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.

-- Regards, Igor Levicki If you find my post helpfull, please rate it and/or select it as a best answer where applies. Thank you.
Bild des Benutzers Feilong H (Intel)

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

Bild des Benutzers Sergey Kostrov

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.

Melden Sie sich an, um einen Kommentar zu hinterlassen.