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

icc 17.0.1 miscompiles valid C code at -O2 and -O3 on x86_64-linux-gnu

Zhendong_Su
Beginner
442 Views

Compiler version and platform: 

Intel(R) C Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.1.132 Build 20161005 

$ icc -Os small.c; ./a.out; echo $?
1
$ 
$ icc -O2 small.c; ./a.out; echo $?
0
$ icc -O3 small.c; ./a.out; echo $?
0
$ 
$ cat small.c
struct S { char f; };

int a, b, *c = &b;

struct S foo ()
{
  struct S d = { 1 };
  for (; a < 1; a++)
    if (d.f)
      *c = 1;
  return d;
}

int main ()
{
  foo ();
  return b; 
}
$ 

 

0 Kudos
0 Replies
Reply