带有SSE内在函数的Clang内存清理程序错误

问题描述

这是一段代码,如果我在启用内存清理程序的clang进行编译和运行,则会生成内部编译器错误。

主要是将一些数据放入SSE寄存器中,并调用将半浮点数转换为浮点数的函数:

int main(int argc,char** argv) {
  // Just some memory to load from.
  alignas(64) std::array<uint16_t,16> array;
  array.fill(0);

  __m128i ints = _mm_set1_epi64x(*reinterpret_cast<const uint64_t*>(array.data()));

  // msan is happy with this version,and both versions work if we compile with anything other than -Og or -O1
  //   __m128i ints = _mm_set_epi64x(*reinterpret_cast<const uint64_t*>(array.data()),0);

  __m128 floats = _mm_cvtph_ps(ints);

  std::array<float,4> p;
  _mm_storeu_ps(p.data(),floats);
  std::cout<< p[0] << p[3] << std::endl;

  return 0;
}

另请参见https://godbolt.org/z/5xva3q-

运行clang10.0.1 -Og -g -std=c++17 -march=haswell -fsanitize=memory -fsanitize-memory-track-origins生成的二进制文件将产生以下输出:

Program returned: 77
==1==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x4a5f00  (/app/output.s+0x4a5f00)
    #1 0x7f1f2b3a0b96  (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #2 0x41f369  (/app/output.s+0x41f369)

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/app/output.s+0x4a5f00) 
  ORIGIN: invalid (0). Might be a bug in MemorySanitizer origin tracking.
    This could still be a bug in your code,too!
Exiting

我不知道为什么会导致错误,并且仅在特定的优化设置下才会发生。对我来说,这似乎是一个潜在的bug虫,但我想与更多的读者确认这一点。

编辑:这似乎在clang的主干版本中已解决。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...