Home Dashboard Directory Help
Search

C++ optimizer fails in debug with /O2 and /Zi by Matthias Mayrock


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 613868
Opened: 10/15/2010 2:32:49 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

The following code succeeds in debug version but fails when compiled in debug version with /O2. I know the mixture is not the most common use-case but we @Ableton use it to get our test suite run faster. It fails in VC2008 and VC2010. When it fails, one of the contained assertions triggers:

#include <assert.h>

template <typename T, int MAXSIZE> class TStaticArray
{
public:
__forceinline T& operator[] (int Index)
{
    assert(Index >= 0 && Index < MAXSIZE);
    return mArray[Index];
}
__forceinline const T& operator[] (int Index) const
{
    assert(Index >= 0 && Index < MAXSIZE);
    return mArray[Index];
}

protected:
T mArray[MAXSIZE];
};

class Foo
{
public:
Foo();
void Bar();

private:
int mPatternLength;
TStaticArray<int, 512> mPattern;
};

Foo::Foo()
: mPatternLength(3)
{}

void Foo::Bar()
{
for (int Index = 0; Index < mPatternLength / 2; Index++)
{
    volatile int Value = mPattern[mPatternLength * 2 - Index - 1];
    mPattern[Index * 2 + 1] = Value;
}
}

int _tmain(int /*argc*/, _TCHAR* /*argv[]*/)
{
Foo c;
c.Bar();

    return 0;
}
Details
Sign in to post a comment.
Posted by Microsoft on 11/30/2010 at 5:51 PM
This is a bug in the VC++ compiler and will be fixed in a future release. Until such time, you can work around this bug by disabling optimizations in the function that exhibits the issue.

You can use this MSDN resource for directions on how to selectively disable optimizations:

http://msdn.microsoft.com/en-us/library/chh3fb0k(v=VS.100).aspx

Mark Levine
Visual C++
Posted by Microsoft on 10/17/2010 at 7:48 PM
Thanks for your feedback.

We are rerouting 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 10/15/2010 at 3:21 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  
EpicFail2010.zip 10/15/2010 1.37 MB