While compiling a C++ windows console application were the Enhanced Instruction Set is enabled to SSE2, we are facing a problem compiling the following code:
struct S1 : public S
int _tmain(int argc, _TCHAR* argv)
S1 *m_pDet = new S1;
m_pDet->a = m_pDet->b = sqrt(128.0);
printf("%f %f\n", m_pDet->a,m_pDet->b);
While running the code, m_pDet->b does not receive the correct value and memory is corrupted in that area. When looking at the disassembly code it seems that the instruction used is MOVUPS. This is due to the pragma pack (1) which if is disabled, then the compiler will use the MOVSS instruction instead which works.
The problem is that MOVUPS is an incorrect instruction. It copies 128bit and not 32bit into the memory.