public
Last active

Found a bug in the Intel compiler.

  • Download Gist
iccbug.c
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
// Code sample illustrating a bug in the Intel compiler
// icpc (ICC) 13.0.1 20121010
 
 
// compile with:
// icc -restrict -std=c99 -O2 iccbug.c -o iccbug
// then run iccbug
// Tested in Linux Ubuntu 12.10 (Intel Core i7)
 
#include <stdint.h>
#include <stdio.h>
 
// expect: out[0] = in[0] + in[1] + in[2] + in[3];
// out[1] = in[4] + in[5] + in[6] + in[7];
__attribute__((noinline))
void broken_with_O2(int * restrict in,
int * out) {
for(int outer = 0; outer < 2; outer++) {
*out = *in++;
for (int inner = 1; inner < 4; inner++) {
*out += *in++;
}
++out;
}
}
 
int main() {
int in[8] = {1,1,1,1,1,1,1,1};
int out[2];
 
broken_with_O2(&in[0],&out[0]);
 
printf(" got = %d %d\n",out[0], out[1]);
printf(" expected = %d %d\n", 4,4);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.