[cfe-dev] clang, C++ and compound literals in SSE2 intrinsics

Chris Lattner clattner at apple.com
Mon Apr 25 12:43:24 PDT 2011


On Apr 23, 2011, at 3:05 AM, Jonathan Sauer wrote:

> Hello,
> 
> compiling some SSE2 code with clang in C++0x mode and "-pedantic", I got the following warning:
> "Compound literals are a C99-specific feature". I looked into the file "emmintrin.h" coming with
> clang, where the warning originated, and _mm_shuffle_epi32 (as well as some other intrinsics)
> indeed uses compound literals (emphasis mine):
> 
> #define _mm_shuffle_epi32(a, imm) \
>  ((__m128i)__builtin_shufflevector((__v4si)(a), (__v4si) {0}, \
>                                                 ^^^^^^^^^^^^
>                                    (imm) & 0x3, ((imm) & 0xc) >> 2, \
>                                    ((imm) & 0x30) >> 4, ((imm) & 0xc0) >> 6))
> 
> 
> The code works correctly, so clang is able to compile it. Still, I'd like to get rid of the false
> warning. IMO there are two possibilities:
> 
> 1. Change emmintrin.h so that the intrinsics are implemented without compound literals (if
>   possible)
> 
> 2. Change emmintrin.h so that the compound literal warning is suppressed just for that file.
> 
> Unfortunately, I don't know to perform either change. I'm not even sure if (2) is currently
> possible with clang at all.

Hi Jonathan,

Warnings are disabled for system headers in general.  The issue here is that he warning is coming from a macro that is instantiated from a system header.  There are two more solutions:

1a: Fix #defines to avoid compound literals.

3. Change the compound literal warning to not fire if the expansion is from a system header.

I'd prefer 1a.

-Chris



More information about the cfe-dev mailing list