VC2008 x64优化错误 [英] VC2008 x64 Optimization bug

查看:83
本文介绍了VC2008 x64优化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在x64上且优化设置为/Ox/Ot的发行版中,以下代码崩溃,并带有无效的参数异常(c0000417).

The following code crashes with an invalid argument exception (c0000417) when compiled in release, on x64 with optimisation set to /Ox /Ot.


#include <vector>

using namespace std;

struct Data
{
 int a;
 int b;
 Data(int a_, int b_)
  :a(a_), b(b_)
 {
 }
};

struct Data2
{
 __int64 a;
 std::vector< Data > entries;
};

#if 1
#define FIX(it) it
#else
#define FIX(it) vector<Data>::iterator(it) 
#endif

class Test
{
private:
 Data2& data;
 vector<Data>::iterator pointer;
public:
 Test(Data2& data_)
  :data(data_)
 {
  pointer = data.entries.begin()+1;
 }

 void erase()
 {
  data.entries.erase(FIX(pointer), data.entries.end());
 }
};

int main(int argc, char* argv[])
{
 Data2 data;
 data.entries.push_back(Data(0,1));
 data.entries.push_back(Data(2,3));
 data.entries.push_back(Data(4,5));
 data.entries.push_back(Data(6,7));
 Test test(data);
 test.erase();
 return 0;
}


推荐答案

在x64上且优化设置为/Ox/Ot的发行版中进行编译时,以下代码因无效的参数异常(c0000417)而崩溃.
...

问题似乎是该方法已内联,并插入了对_SCL_SECURE_VALIDATE的额外调用.

将迭代器成员包装在临时副本中似乎可以解决此问题.

我无法在vs2010中重现该问题,但这可能仅仅是因为vector的实现已更改,而vs2010似乎没有内联擦除(可能太大了吗?)

The following code crashes with an invalid argument exception (c0000417) when compiled in release, on x64 with optimisation set to /Ox /Ot.
...

the problem seems to be that the method is inlined and an extra call to _SCL_SECURE_VALIDATE is inserted.

Wrapping the iterator member in a temporary copy seems to fix the problem.

I haven't been able to reproduce the problem in vs2010 but that may simply be that the implementation of vector has changed and vs2010 doesn't seem to inline erase (maybe it is too big?)

艾伦,你好

我通常建议报告此情况(使用一个简单的项目来制作
在Connect网站上访问MS:
https://connect.microsoft.com/VisualStudio ,但是我注意到它们
不再有VS2008的报告表格.

I'd normally suggest reporting this (with a simple project to make
someone's life easier) to MS on the Connect site:
https://connect.microsoft.com/VisualStudio , however I note that they
no longer have a report form for VS2008.

您是否曾尝试修饰要使用的标头定义
__forceinline看看这是否会影响VS2010编译器的优化
并在那里复制问题?

Have you tried fiddling the header definition of erase to use
__forceinline to see if that affects the VS2010 compiler optimisation
and reproduces the issue there?

戴夫


这篇关于VC2008 x64优化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆