ICPC produces wrong binary !

ICPC produces wrong binary !

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];
if (m.size() == 0)
return 0;

7 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

comment deleted --Vladimir

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.
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.

Double post, this was not possible with old forum.

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.

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.


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.

Leave a Comment

Please sign in to add a comment. Not a member? Join today