简体   繁体   English

__m256 阵列上的 Visual Studio 2019 C6385 / C6386(缓冲区溢出警告)

[英]Visual Studio 2019 C6385 / C6386 (buffer overrun warning) on __m256 array

I'm allocating an array as follows:我正在分配一个数组,如下所示:

__m256 *v256f_valid_mask = (__m256*)malloc(sizeof(__m256) * p_ranks);

The compiler is showing warning C6385 / C6386 (depending on exact context) on all lines where I access this array, except for at [0] , indicating that 64 bytes may be read.编译器在我访问该数组的所有行上都显示警告 C6385 / C6386(取决于确切的上下文),除了[0] ,表明可以读取 64 个字节。 The definition clearly states it's an array of 32-byte values.该定义明确指出它是一个 32 字节值的数组。

Using _aligned_malloc() doesn't help.使用_aligned_malloc()没有帮助。

Sample code to reproduce the warning:重现警告的示例代码:

void func(const size_t p_ranks)
{
    __m256 v256f_x = _mm256_set1_ps(1.0f);
    __m256* v256f_valid_mask = (__m256*)malloc(sizeof(__m256) * p_ranks);

    for (size_t rank = 1; rank < p_ranks; rank++)
    {
        v256f_valid_mask[rank] = _mm256_cmp_ps(v256f_x, _mm256_setzero_ps(), _CMP_GT_OQ); // <<
    }
}

Exact warning:确切警告:

I fixed the C6011 warning with a null check.我用空检查修复了 C6011 警告。

Is there an error in my code or is this a false positive?我的代码中有错误还是误报?

It is a false positive but the code analyser doesn't know it (probably because it doesn't 'trust' the malloc() call)!这是一个误报,但代码分析器不知道(可能是因为它不“信任” malloc() 调用)! Using 'new' instead clears the warning (at least, in my VS2019 solution) …使用“new”来清除警告(至少,在我的 VS2019 解决方案中)……

void func(const size_t p_ranks)
{
    __m256 v256f_x = _mm256_set1_ps(1.0f);
//  __m256* v256f_valid_mask = (__m256*)malloc(sizeof(__m256) * p_ranks);
    #if defined(__cplusplus)
    __m256* v256f_valid_mask = new __m256[p_ranks];
    #else
    #define MAXRANKS 100 // Would probably be defined elsewhere!
    __m256 v256f_valid_mask[MAXRANKS];
    #endif

    for (size_t rank = 1; rank < p_ranks; rank++)
    {
        v256f_valid_mask[rank] = _mm256_cmp_ps(v256f_x, _mm256_setzero_ps(), _CMP_GT_OQ); // <<
    }
}

Please try and see!请试试看!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM