Bug in x86 inline assembly to watch out for


Imagine this very lame code:

int main() {}

void BugAsm()
{
__asm {
MOV [ESP+12],OFFSET main
}
}

void(*BugAsmPt)()=&BugAsm; // this is just to make sure the function is not removed by /OPT:REF


Now imagine your significantly less lame code doing something similar.
Now imagine that the compiler crashes with a bizzare message about “x86\code.c” something or other.


Well, you can fix this problem by changing the assembly code to this:


mov DWORD PTR[esp+12], OFFSET main


Another unfixed bug, worked around 😐


-Kev

Comments (2)

  1. and the path ‘f:rtmvctoolscompilerutcsrcP2x86code.c’ in the error message does not seem to be referring to a local file …

  2. Yuhong Bao says:

    No, it refers to a file on the machine that the compiler was built.