The compiled code generated for the following C++ example produces different output between the Debug and Release configurations. It should print out "0 1 2 3", but the Release build actually prints out "0 0 2 3". Stepping through in the debugger, it appears the snippetfor(int i = 0; i < 4; i++) accumulate[i] += new_vals[i];is where it goes wrong, as it appears to get compiled too be the equivalent ofaccumulate[0] += new_vals[0]accumulate[1] += new_vals[0]accumulate[2] += new_vals[2]accumulate[3] += new_vals[3]Note, this behaviour seems to be affected by what the "Whole Program Optimization" option is set too. The incorrect behaviour of the Release build is seen when this is set to "No Whole Program Optimization", but the behaviour is correct if this is set to "Use Link Time Code Generation"Example program:#include <cstdio>// expected output // 0 1 2 3// Release build with "Whole Program Optimization" disabled outputs// 0 0 2 3class foo{public: foo() { for(int i = 0; i < 4; i++) accumulate[i] = 0; } short accumulate[4]; void load_new_vals(char new_vals[4]); void test();};void foo::load_new_vals(char new_vals[4]){ for(int i = 0; i < 4; i++) { new_vals[i] = i; }}void foo::test(){ char new_vals[4]; load_new_vals(new_vals); for(int i = 0; i < 4; i++) accumulate[i] += new_vals[i]; printf("%d %d %d %d\n", accumulate[0], accumulate[1], accumulate[2], accumulate[3]);}int main(int argc, char** argv){ foo bar; bar.test(); return 0;}
Visual Studio/Team Foundation Server/.NET Framework Tooling version
Steps to reproduce
Product Language
Operating System
Operating System Language
Actual results
Expected results
Please wait...