错误 : 尚无法编译此意外的强制转换值

Error : cannot compile this unexpected cast lvalue yet

本文关键字:转换 意外 编译 错误      更新时间:2023-10-16

我正在针对 Apple Clang 进行测试,遇到了过去从未经历过的错误。代码如下,如果缺少_mm_set_epi64x,它将替换内部代码。

#if defined(__clang__)
#  define GCC_INLINE inline
#  define GCC_INLINE_ATTRIB __attribute__((__gnu_inline__, __always_inline__))
#elif (GCC_VERSION >= 30300) || defined(__INTEL_COMPILER)
#  define GCC_INLINE __inline
#  define GCC_INLINE_ATTRIB __attribute__((__gnu_inline__, __always_inline__, __artificial__))
#else
#  define GCC_INLINE inline
#  define GCC_INLINE_ATTRIB
# endif
...
GCC_INLINE __m128i GCC_INLINE_ATTRIB
MM_SET_EPI64X(const word64 a, const word64 b)
{
    const word64 t[2] = {b,a}; __m128i r;
    asm ("movdqu %1, %0" : "=x"(r) : "m"(t));
    return r;
}

错误是:

c++ -DNDEBUG -g2 -O2 -c sha.cpp
In file included from sha.cpp:24:
./cpu.h:689:39: error: cannot compile this unexpected cast lvalue yet
        asm ("movdqu %1, %0" : "=x"(r) : "m"(t));

苹果叮当版本是:

$ c++ --version
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

根据Clang Bug 20201,该问题已经修复。我对 20201 错误的问题是:

  1. 我不知道是不是同一个问题
  2. 问题没有解释
  3. 未提供解决方法
  4. 苹果已经放弃了其软件

由于(4(,我必须尝试修复它。由于(2(和(3(,我不知道如何解决它。

问题是什么,我该如何解决?

好吧,随机猜测时间,但它似乎有效...环顾相关的错误报告,有这样一篇文章说:

这是通过从非类右值中删除 cv 限定符的工作修复的。

这向我表明,内部结构中还残留着一些const属性,所以像这样:

word64 a1 = a, b1 = b;
word64 t[2] = {b1,a1};

可能起作用,因为通过复制到显式声明的非const变量中,可以防止abconst传播,希望如此。OP已确认这是有效的,因此他们的最终解决方案在这里为后代提供:

GCC_INLINE __m128i GCC_INLINE_ATTRIB
MM_SET_EPI64X(const word64 a, const word64 b)
{
#if defined(__clang__)
    word64 t1 = a, t2 = b; 
    const word64 t[2] = {t2,t1}; __m128i r;
    asm ("movdqu %1, %0" : "=x"(r) : "m"(t));
    return r;
#else
    const word64 t[2] = {b,a}; __m128i r;
    asm ("movdqu %1, %0" : "=x"(r) : "m"(t));
    return r;
#endif
}