Created
December 13, 2013 18:35
-
-
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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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 : } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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