jww jww -4 years ago 62
C++ Question

Error : cannot compile this unexpected cast lvalue yet

I'm testing against Apple Clang and I'm encountering an error I have not experienced in the past. The code is as follow, and it replaces the

_mm_set_epi64x
intrinsic if its missing.

#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;
}


The error is:

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));


The Apple Clang version is:

$ 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


According to Clang Bug 20201, the issue is already fixed. My problems with the 20201 bug are:


  1. I don't know if its the same issue

  2. the problem is not explained

  3. a workaround is not offered

  4. Apple has abandoned its software



Because of (4), I have to attempt to fix it. Because of (2) and (3), I don't know how to fix it.

What is the problem, and how do I fix it?

Answer Source

OK, random guessing time, but it seems to work... Looking around at related bug reports, there is this posting that says:

This was fixed by the work to remove cv-qualifiers from non-class rvalues.

This suggests to me that there is some const attribute left hanging around in internal structures, so something like this:

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

Might work, as by copying into an explicitly-declared non-const variable, the propagation of the constness of a and b is prevented, hopefully. This has been confirmed as working by the OP, so their final solution is presented here for posterity:

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
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download