Home Dashboard Directory Help
Search

C++ /O2 compiler bug by Mathieu Lamarre


Status: 

Closed


1
0
Sign in
to vote
Type: Bug
ID: 805849
Opened: 10/18/2013 9:06:44 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

// The following code should produce identical output for two distinct implementations of f(x) = 2x - 1
// In Visual Studio 2012 Update 3, release build (/O2), implement A foo_version_A gives wrong results
// VLAM inc 2013
// Mathieu Lamarre
#include <iostream>

namespace
{
    const int NELEMENTS = 10;

    class Bar
    {
    public:
        Bar()
        :m_x(0.0)
        {
        }

        double m_x;
        double m_other; // without the other no bug
    };

    void foo_version_A( Bar *pts, int n )
    {
        for (int i = 0; i < n; ++i)
        {
         pts[i].m_x *= 2.0;
         pts[i].m_x -= 1.0;
        }
    }

    void foo_version_B( Bar *pts, int n )
    {
        for (int i = 0; i < n; ++i)
        {
         pts[i].m_x = 2.0 * pts[i].m_x - 1.0;
        }
    }
}

int main(void)
{
    Bar dataA[NELEMENTS];
    Bar dataB[NELEMENTS];
    
    for (int i = 0; i < NELEMENTS; ++i)
    {
        dataA[i].m_x = i + 1.0;
        dataB[i].m_x = i + 1.0;
    }

    foo_version_A( dataA, NELEMENTS );
    foo_version_B( dataB, NELEMENTS );
    
    for (int i = 0; i < NELEMENTS; ++i)
    {
        std::cout << "A:\t" << dataA[i].m_x << "\tB:\t" << dataB[i].m_x << std::endl;
    }
}
Details
Sign in to post a comment.
Posted by Microsoft on 11/6/2013 at 10:14 AM
Hi Mathieu, thanks for the bug report.

This is a bug in the VS 2012 compiler optimizer. It is the same issue as the one here: http://connect.microsoft.com/VisualStudio/feedback/details/774941/problem-with-compiler-optimization

With our current workload, looking at the existing bugs, and with the knowledge that the bug is fixed in VS 2013, we currently do not plan on fixing this issue in VS 2012.

If this issue is severe, causing critical business situations or blocking your product development or deployment, please go to http://support.microsoft.com or call 1-800-MICROSOFT for assistance. For Microsoft premier customers, please contact your administrator, your Technical Account Manager, or your Microsoft premier account representative.

I am closing this MSConnect item.

Thanks,
Eric Brumer - Microsoft Visual C++ Team
Posted by Microsoft on 10/21/2013 at 6:37 AM
Hi Mathieu,

Thanks for your quick response. Sorry for the inconvenience. We could repro the issue with VS2012.3 and VS2012.4. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Mathieu Lamarre on 10/21/2013 at 6:20 AM
Please don't close a bug in the middle of the night in the timezone where it was submitted.

This is a Visual Studio 2012 Update 3 and Update 4 RC bug please try to reproduce it with these versions.

Build the attached cpp in Release with VS 2012 Update 4 RC (cl.exe version 17.00.60930)
Posted by Microsoft on 10/21/2013 at 2:33 AM
Thank you for submitting feedback on Visual Studio and .NET Framework. According to your description, we will close this case. Should you find any bugs in the future, please feel free to let us know.

Thanks,
Microsoft Visual Studio Connect Support Team
Posted by Microsoft on 10/21/2013 at 2:31 AM
Thank you for submitting feedback on Visual Studio and .NET Framework. According to your description, we will close this case. Should you find any bugs in the future, please feel free to let us know.

Thanks,
Microsoft Visual Studio Connect Support Team
Posted by UnitUniverse on 10/19/2013 at 3:40 AM
* marks: Seems fine in vs2013rtm
Posted by Microsoft on 10/18/2013 at 11:51 AM
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  
compiler_bug.cpp 10/18/2013 1 KB