Skip to content

Instantly share code, notes, and snippets.

@bionicbeagle
Created December 13, 2013 18:35
Show Gist options
  • Save bionicbeagle/7948974 to your computer and use it in GitHub Desktop.
Save bionicbeagle/7948974 to your computer and use it in GitHub Desktop.
VS2013 x64 compiler bug Note how the access to m_size (loaded into edx) is reordered to be after the detachBuffer() call:
; 12 : {
$LN6:
sub rsp, 40 ; 00000028H
; 13 : AllocatingBuffer outBuf;
lea rcx, QWORD PTR outBuf$[rsp]
call ??0AllocatingBuffer@@QEAA@XZ ; AllocatingBuffer::AllocatingBuffer
; 14 : int size = outBuf.size();
; 15 : create(outBuf.detachBuffer(), size);
lea rcx, QWORD PTR outBuf$[rsp]
call ?detachBuffer@AllocatingBuffer@@QEAAPEADXZ ; AllocatingBuffer::detachBuffer
mov edx, DWORD PTR outBuf$[rsp]
mov rcx, rax
call ?create@@YAPEAVSharedBuffer@@PEADH@Z ; create
; 16 : }
// Compile using VS2013 x64 with "cl /c /FAs /O2 bug.cpp"
//
// Note how the access to m_size is reordered to be after the detachBuffer() call
struct AllocatingBuffer
{
AllocatingBuffer();
char* detachBuffer();
int size() { return m_size; }
int m_size;
};
class SharedBuffer* create(char* memory, int size);
void acquireInfoFromBuffer()
{
AllocatingBuffer outBuf;
int size = outBuf.size();
create(outBuf.detachBuffer(), size);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment