【问题标题】:Error : cannot compile this unexpected cast lvalue yet错误:还不能编译这个意外的转换左值
【发布时间】:2017-10-21 15:24:14
【问题描述】:

我正在针对 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));

Apple Clang 版本是:

$ 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. Apple 已放弃其软件

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

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

【问题讨论】:

  • 我现在无法访问错误数据库,但是查看this post,也许有某种 const 问题?如果从word64 t[2] = {b,a}; 中删除const 会发生什么?
  • 谢谢肯。删除 const 并没有解决问题。
  • 继续我的疯狂猜测,word64 a1 = a, b1 =b; word64 t[2] = {b1,a1};?或者从原型中删除consts?否则,我完全没有猜测!

标签: c++ macos inline-assembly clang++


【解决方案1】:

好的,随机猜测时间,但它似乎工作......环顾相关的错误报告,有this posting说:

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

这表明我在内部结构中保留了一些 const 属性,所以是这样的:

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

可能会起作用,因为通过复制到显式声明的非const 变量,a 和b 的constness 的传播被阻止,希望如此。这已被 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
}

【讨论】:

  • 谢谢。 CentOS 5/GCC 4.1 失败,“内存输入 1 不可直接寻址”。看起来这个问题比 Clang 更大。也许我需要寻找_mm_set_epi64x 的用途并尝试将它们转换为_mm_set_epi64。我认为唯一的区别是 a 和 b 的论点是相反的。或者可能是 memcpy 它(我似乎记得 SunCC 使用 memcpy... 生成错误代码。
  • 看this question,你不能使用数组,而是应该使用struct { word64 t[2]; }t = {t2, t1};或类似的东西,或者使用_mm128类型。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-17
  • 1970-01-01
  • 1970-01-01
  • 2011-02-15
  • 1970-01-01
  • 2014-09-14
相关资源
最近更新 更多