Created
April 16, 2012 19:29
-
-
Save zeux/2400940 to your computer and use it in GitHub Desktop.
MSVC10 optimization bug
This file contains hidden or 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
// cl 16.00.40219.01 for 80x86 | |
// Compile with /O2: | |
// pData - slcControlFlags = 48 | |
// Assertion failed: (pData - slcControlFlags) == sizeof(slcControlFlags), file msvc10optbug.cpp, line 46 | |
#include <stdint.h> | |
#include <assert.h> | |
#include <string.h> | |
#include <stdio.h> | |
const size_t kSlcSizeWithoutBoneArray = 96; | |
struct Locator { char data[16]; }; | |
__declspec(noinline) | |
void WriteFlagsAt(uint8_t (&slcControlFlags)[kSlcSizeWithoutBoneArray], int controlSlot, const Locator& locator) | |
{ | |
// create working handle | |
uint8_t* pData = slcControlFlags; | |
// locator | |
for ( int i = 0; i < 4; ++i ) | |
{ | |
if (i == controlSlot) | |
{ | |
memcpy(pData, &locator, sizeof(locator)); | |
} | |
pData += sizeof(locator); | |
} | |
// masks | |
for (int i = 0; i < 4; ++i) | |
{ | |
if (i == controlSlot) | |
{ | |
*((uint32_t*)pData) = 0; | |
} | |
pData += sizeof(uint32_t); | |
} | |
// indices | |
for (int i = 0; i < 4; ++i) | |
{ | |
if (i == controlSlot) | |
{ | |
*((uint32_t*)pData) = 0; | |
} | |
pData += sizeof(uint32_t); | |
} | |
printf("pData - slcControlFlags = %d\n", (int)(pData - slcControlFlags)); | |
assert( (pData - slcControlFlags) == sizeof(slcControlFlags) ); | |
} | |
int main() | |
{ | |
uint8_t dest[kSlcSizeWithoutBoneArray]; | |
WriteFlagsAt(dest, 1, Locator()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment