Hi, The xmmintrin.h and related header files make use of altivec.h to enable vector intrinsics to be used for compatibility. However, for C++ or C11 using strict ANSI compliance, this causes a collision with the "bool" keyword. We intend to later change altivec.h to not define these keywords under those conditions, but this could cause a certain amount of community churn, so we want to try a distro build with this before making such a change in GCC 9. Since these compatibility headers are new in GCC 8, we can safely undefine these following the include of altivec.h without disturbing existing code.
Note that for strict-ANSI C11 code, stdbool.h must be included after including xmmintrin.h in order to enable the bool keyword. When we later fix altivec.h to not define them in the first place, this ordering requirement will no longer exist. While testing, I discovered a couple stray instances of "vector" that should have been "__vector" in these headers. Fixes for those are included in this patch. I also updated the gcc.target/powerpc/powerpc.exp file to allow C++ tests to be placed in that directory (with a *.C suffix). Bootstrapped and tested on powerpc64le-linux-gnu with no regressions. Is this okay for trunk? Thanks, Bill [gcc] 2018-04-02 Bill Schmidt <wschm...@linux.ibm.com> * config/rs6000/emmintrin.h (_mm_cvtpd_epi32): Use __vector rather than vector. (_mm_cvtpd_ps): Likewise. (_mm_cvttpd_epi32): Likewise. * config/rs6000/mmintrin.h (_mm_unpacklo_pi8): Likewise. * config/rs6000/xmmintrin.h: For strict-ANSI C++ or C11, undefine vector, pixel, and bool following altivec.h include. [gcc/testsuite] 2018-04-02 Bill Schmidt <wschm...@linux.ibm.com> * gcc.target/powerpc/powerpc.exp: Add .C suffix for main loop. * gcc.target/powerpc/undef-bool.C: New file. * gcc.target/powerpc/undef-bool.c: New file. Index: gcc/config/rs6000/emmintrin.h =================================================================== --- gcc/config/rs6000/emmintrin.h (revision 258958) +++ gcc/config/rs6000/emmintrin.h (working copy) @@ -885,7 +885,7 @@ _mm_cvtpd_epi32 (__m128d __A) #ifdef _ARCH_PWR8 temp = vec_mergeo (temp, temp); - result = (__v4si)vec_vpkudum ((vector long)temp, (vector long)vzero); + result = (__v4si)vec_vpkudum ((__vector long)temp, (__vector long)vzero); #else { const __v16qu pkperm = {0x00, 0x01, 0x02, 0x03, 0x08, 0x09, 0x0a, 0x0b, @@ -919,7 +919,7 @@ _mm_cvtpd_ps (__m128d __A) #ifdef _ARCH_PWR8 temp = vec_mergeo (temp, temp); - result = (__v4sf)vec_vpkudum ((vector long)temp, (vector long)vzero); + result = (__v4sf)vec_vpkudum ((__vector long)temp, (__vector long)vzero); #else { const __v16qu pkperm = {0x00, 0x01, 0x02, 0x03, 0x08, 0x09, 0x0a, 0x0b, @@ -947,7 +947,7 @@ _mm_cvttpd_epi32 (__m128d __A) #ifdef _ARCH_PWR8 temp = vec_mergeo (temp, temp); - result = (__v4si)vec_vpkudum ((vector long)temp, (vector long)vzero); + result = (__v4si)vec_vpkudum ((__vector long)temp, (__vector long)vzero); #else { const __v16qu pkperm = {0x00, 0x01, 0x02, 0x03, 0x08, 0x09, 0x0a, 0x0b, Index: gcc/config/rs6000/mmintrin.h =================================================================== --- gcc/config/rs6000/mmintrin.h (revision 258958) +++ gcc/config/rs6000/mmintrin.h (working copy) @@ -317,7 +317,7 @@ _mm_unpacklo_pi8 (__m64 __m1, __m64 __m2) a = (__vector unsigned char)vec_splats (__m1); b = (__vector unsigned char)vec_splats (__m2); c = vec_mergel (a, b); - return (__builtin_unpack_vector_int128 ((vector __int128_t)c, 1)); + return (__builtin_unpack_vector_int128 ((__vector __int128_t)c, 1)); #else __m64_union m1, m2, res; Index: gcc/config/rs6000/xmmintrin.h =================================================================== --- gcc/config/rs6000/xmmintrin.h (revision 258958) +++ gcc/config/rs6000/xmmintrin.h (working copy) @@ -58,6 +58,18 @@ #define _XMMINTRIN_H_INCLUDED #include <altivec.h> + +/* Avoid collisions between altivec.h and strict adherence to C++ and + C11 standards. This should eventually be done inside altivec.h itself, + but only after testing a full distro build. */ +#if defined(__STRICT_ANSI__) && (defined(__cplusplus) || \ + (defined(__STDC_VERSION__) && \ + __STDC_VERSION__ >= 201112L)) +#undef vector +#undef pixel +#undef bool +#endif + #include <assert.h> /* We need type definitions from the MMX header file. */ Index: gcc/testsuite/gcc.target/powerpc/powerpc.exp =================================================================== --- gcc/testsuite/gcc.target/powerpc/powerpc.exp (revision 258958) +++ gcc/testsuite/gcc.target/powerpc/powerpc.exp (working copy) @@ -35,7 +35,7 @@ if ![info exists DEFAULT_CFLAGS] then { dg-init # Main loop. -dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] \ +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cCS\]]] \ "" $DEFAULT_CFLAGS set SAVRES_TEST_OPTS [list -Os -O2 {-Os -mno-multiple} {-O2 -mno-multiple}] Index: gcc/testsuite/gcc.target/powerpc/undef-bool.C =================================================================== --- gcc/testsuite/gcc.target/powerpc/undef-bool.C (nonexistent) +++ gcc/testsuite/gcc.target/powerpc/undef-bool.C (working copy) @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -std=c++11 -DNO_WARN_X86_INTRINSICS" } */ + +/* Test to ensure that "bool" gets undef'd in xmmintrin.h when + we require strict ANSI. */ + +#include <xmmintrin.h> + +bool foo (int x) +{ + return x == 2; +} + Index: gcc/testsuite/gcc.target/powerpc/undef-bool.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/undef-bool.c (nonexistent) +++ gcc/testsuite/gcc.target/powerpc/undef-bool.c (working copy) @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -std=c11 -DNO_WARN_X86_INTRINSICS" } */ + +/* Test to ensure that "bool" gets undef'd in xmmintrin.h when + we require strict ANSI. Subsequent use of bool needs stdbool.h. + altivec.h should eventually avoid defining bool, vector, and + pixel, following distro testing. */ + +#include <xmmintrin.h> + +bool foo (int x) /* { dg-error "unknown type name 'bool'; did you mean '_Bool'?" } */ +{ + return x == 2; +} +