0

We are testing under Sun Studio 12.3. We are catching a compiler error that's not present under 12.4 and later. Its not present under 12.1 and earlier, but that's because the compiler has trouble with AES instructions. Its also not present under other compilers, like Clang, GCC, ICPC and VC++. The error is:

/opt/solarisstudio12.3/bin/CC -DDEBUG -g3 -xO0 -D__SSE2__ -D__SSE3__ -D__SSSE3__ \
-D__SSE4_1__ -D__SSE4_2__ -D__AES__ -D__PCLMUL__ -D__RDRND__ -D__RDSEED__ -D__AVX__ \
-D__AVX2__ -D__BMI__ -D__BMI2__  -native -m64 -KPIC -template=no%extdef -c rijndael.cpp

"/opt/solarisstudio12.3/prod/include/CC/Cstd/algorithm", line 283: Error: Cannot use vector unsigned long long[2] to initialize vector unsigned long long[2].
"rijndael.cpp", line 277:     Where: While instantiating "std::swap<vector unsigned long long[2]>(unsigned long long(&)[2], unsigned long long(&)[2])".
"rijndael.cpp", line 277:     Where: Instantiated from non-template code.
1 Error(s) detected.
gmake: *** [rijndael.o] Error 2
gmake: *** Waiting for unfinished jobs....
ERROR: failed to make cryptest.exe

The code in question is:

std::swap(*(__m128i*)(rk), *(__m128i*)(rk+4*m_rounds));

I have a couple of questions:

  • What is the compiler having trouble with?
  • What is the best way to clear the error?

I have to ask the second question because I'm not sure of SunCC and the __m128i type given I could use raw memcpy, try to write my own swap, or even try an iter_swap without the dereference.

Community
  • 1
  • 1
jww
  • 97,681
  • 90
  • 411
  • 885
  • 1
    Support for `std::swap` with C-arrays was added in C++11; have you enabled C++11/14 for your compiler? – ildjarn Jul 17 '16 at 01:47
  • @ildjarn - Ah, thank you very much. I believe Sun Studio 12.2 is C++03 only. In this case, how does one write a swap given `__m128i` is opaque? Should I simply `memcpy` it? – jww Jul 17 '16 at 01:53
  • The general implementation of `swap` will typically create a temporary like `T temp( b );` where `b` is a formal argument of reference type. Prior to C++11 this would be invoked for raw arrays as actual arguments. And that doesn't compile (just like `int x[3]; int y[3]( x );` doesn't compile). – Cheers and hth. - Alf Jul 17 '16 at 01:54
  • @ildjarn - you should probably provide an answer. You provided the critical piece of information by answering *"What is the compiler having trouble with?"*. I did not realize it was non-standard, and every other compiler accepts it (even Sun Studio 12.3, which is also C++03). – jww Jul 17 '16 at 02:07
  • @jww : I'd rather not, given I don't have a good solution for you. But feel free to self-answer with whatever details you think are pertinent. :-] – ildjarn Jul 17 '16 at 02:11
  • 1
    Now related: [How to swap two __m128i variables in C++03 given its an opaque type and an array?](http://stackoverflow.com/q/38417413) – jww Jul 17 '16 at 02:42

0 Answers0