Hi,
just found a bug in vc 2003 c++ (and c ) compiler. The problem happens when i use shorts to iterate over a vector and when speed optimization is turned on. The problem is that full 4-byte register is used for indexing the vector and the upper part of the register can contain garbage. The code works well in debug mode, the poblem arises only when I turn on speed optimization.
Let me know if this is an unknown dug - I'll provide details.
BR
Vladimir

a compiler bug
Saul Silos
Once you a reproducible case, please log the issue at http://lab.msdn.microsoft.com/productfeedback/default.aspx so that the owners would take a look.
Thanks, Ayman Shoukry VC++ TeamLeslie Roblin
Well, it's VC7.1. Bugs were fixed between VC7.1 and VC8 (2005), but this still needs to be investigated for a possible VS2003 SP2. Could you post the code here (trimmed down if possible) and the compiler flags you used
Thanks.
Brian
SoCalWizard
WackoWolf
// min = -1
// max = 1
// prev_min = prev_max = 0
for(short s = min; s <= max; s++) {
if((s >= prev_min) && (s <= prev_max)) {
continue;
}
alphas
// add looks like this->_seq
// add also makes some arithmetics which is not very obvious so i skipped it
// i mention it because you'll see it in disassembly
}
here's compiler settings:
/O2 /I "include" /I "..\vmanip\include" /I "..\arith\include" /I "..\alphabets\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /EHsc /ML /GS /Fo"Release/" /Fd"Release/vc70.pdb" /W3 /nologo /c /Zi /TP
and here's disassembly with my comments:
for(short s = min; s <= max; s++) {
00405DD6 cmp cx,dx
00405DD9 mov ebx,ecx
00405DDB jg buildAlphabets+0D9h (405E29h)
00405DDD movzx edi,cx // edi will contain invalid value, initially cx = 0xffff ( short -1)
00405DE0 shl edi,2 // make it index for vector<size_t>
// so after shift edi = 0x3fffc, which is still ok
if((s >= prev_min) && (s <= prev_max)) {
00405DE3 cmp bx,word ptr [esp+10h]
00405DE8 jl buildAlphabets+0A1h (405DF1h)
00405DEA cmp bx,word ptr [esp+14h]
00405DEF jle buildAlphabets+0CEh (405E1Eh)
continue;
}
alphas
00405DF1 mov eax,dword ptr [esi]
00405DF3 inc dword ptr [eax+18h]
00405DF6 mov esi,dword ptr [eax+4]
00405DF9 mov ebp,dword ptr [esi+edi] // this is where indexing occurs
00405DFC sub dword ptr [eax+10h],ebp
00405DFF add esi,edi
00405E01 mov dword ptr [esi],1
00405E07 mov esi,dword ptr [eax+4]
00405E0A mov ebp,dword ptr [eax+10h]
00405E0D add esi,edi
00405E0F mov esi,dword ptr [esi]
00405E11 add ebp,esi
00405E13 mov esi,dword ptr [esp+1Ch]
00405E17 mov dword ptr [eax+10h],ebp
00405E1A mov ebp,dword ptr [esp+18h]
00405E1E inc ebx
00405E1F add edi,4 // here's the line which causes the problem.
// as we iterate over, edi has values:
// 1. 0x3fffc - ok
// 2. 0x40000 - invalid (should be 0x00000)
// but skipped by app. logics
// (compiler uses bx == dx to test - see the line below)
// 3. 0x40004 - invalid (should be 0x00004)
// used as index at 00405DF9
00405E22 cmp bx,dx
00405E25 jle buildAlphabets+93h (405DE3h)
for(short s = min; s <= max; s++) {
00405E27 xor edi,edi
}
C# Intermediate programmer
You should give me complete code (but short as possible). The assumptions I have to make (definitions of prev_min and alphas for instance) can make the difference btw seeing the problem and not. For now, I'll wait until you furnish this. Also use spaces so emoticons are not used by the forums editor.
An example of why it's important to have a complete reproduction of the problem:
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=392077&SiteID=1
When one is pushed to create a compact reproduction, one may find the real cause...
Brian