Home Dashboard Directory Help
Search

Bug in C++ compilation for structures compiled with pragma pack (1) by Oded5119


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 629550
Opened: 12/7/2010 12:48:58 PM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

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:

#include <math.h>

#pragma pack(1)

struct S
{
    float a;
    float b;
};
struct S1 : public S
{
    float c;
};


#pragma pack()

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);
return 0;
}

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.
Details
Sign in to post a comment.
Posted by Oded5119 on 12/14/2010 at 3:35 AM
I have added a zip file containing the project the produces the problem. It happens many times and on different computers.

Please note that it is important to have the /arch:SSE2 switch enabled for this to happen
Posted by Microsoft on 12/7/2010 at 6:05 PM
Thanks for your feedback.
We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 12/7/2010 at 1:25 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
TestSSE.zip 12/14/2010 6 KB
TestSSE.zip 12/14/2010 6 KB