Maybe we should teach Clang not to warn on shadowing if the declaration and
all its uses come from the same macro expansion?


On Mon, Oct 7, 2013 at 4:51 PM, Ted Kremenek <[email protected]> wrote:

> Author: kremenek
> Date: Mon Oct  7 18:51:11 2013
> New Revision: 192143
>
> URL: http://llvm.org/viewvc/llvm-project?rev=192143&view=rev
> Log:
> Suppress useless -Wshadow warning when using _mm* macros from emmintrin.h
>
> Fixes <rdar://problem/10679282>.
>
> I'm not completely satisfied with this patch.  Sprinkling "diagnostic
> ignored"
> _Pragmas throughout this file is gross, but I couldn't suppress
> it for the entire file.
>
> Modified:
>     cfe/trunk/lib/Headers/emmintrin.h
>     cfe/trunk/test/Sema/warn-shadow.c
>
> Modified: cfe/trunk/lib/Headers/emmintrin.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/emmintrin.h?rev=192143&r1=192142&r2=192143&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Headers/emmintrin.h (original)
> +++ cfe/trunk/lib/Headers/emmintrin.h Mon Oct  7 18:51:11 2013
> @@ -826,7 +826,9 @@ _mm_xor_si128(__m128i __a, __m128i __b)
>  }
>
>  #define _mm_slli_si128(a, count) __extension__ ({ \
> +  _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored
> \"-Wshadow\""); \
>    __m128i __a = (a); \
> +   _Pragma("clang diagnostic pop"); \
>    (__m128i)__builtin_ia32_pslldqi128(__a, (count)*8); })
>
>  static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
> @@ -891,7 +893,9 @@ _mm_sra_epi32(__m128i __a, __m128i __cou
>
>
>  #define _mm_srli_si128(a, count) __extension__ ({ \
> +  _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored
> \"-Wshadow\""); \
>    __m128i __a = (a); \
> +  _Pragma("clang diagnostic pop"); \
>    (__m128i)__builtin_ia32_psrldqi128(__a, (count)*8); })
>
>  static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
> @@ -1280,20 +1284,26 @@ _mm_movemask_epi8(__m128i __a)
>  }
>
>  #define _mm_shuffle_epi32(a, imm) __extension__ ({ \
> +  _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored
> \"-Wshadow\""); \
>    __m128i __a = (a); \
> +  _Pragma("clang diagnostic pop"); \
>    (__m128i)__builtin_shufflevector((__v4si)__a, (__v4si)
> _mm_set1_epi32(0), \
>                                     (imm) & 0x3, ((imm) & 0xc) >> 2, \
>                                     ((imm) & 0x30) >> 4, ((imm) & 0xc0) >>
> 6); })
>
>  #define _mm_shufflelo_epi16(a, imm) __extension__ ({ \
> +  _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored
> \"-Wshadow\""); \
>    __m128i __a = (a); \
> +  _Pragma("clang diagnostic pop"); \
>    (__m128i)__builtin_shufflevector((__v8hi)__a, (__v8hi)
> _mm_set1_epi16(0), \
>                                     (imm) & 0x3, ((imm) & 0xc) >> 2, \
>                                     ((imm) & 0x30) >> 4, ((imm) & 0xc0) >>
> 6, \
>                                     4, 5, 6, 7); })
>
>  #define _mm_shufflehi_epi16(a, imm) __extension__ ({ \
> +  _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored
> \"-Wshadow\""); \
>    __m128i __a = (a); \
> +  _Pragma("clang diagnostic pop"); \
>    (__m128i)__builtin_shufflevector((__v8hi)__a, (__v8hi)
> _mm_set1_epi16(0), \
>                                     0, 1, 2, 3, \
>                                     4 + (((imm) & 0x03) >> 0), \
> @@ -1386,8 +1396,10 @@ _mm_movemask_pd(__m128d __a)
>  }
>
>  #define _mm_shuffle_pd(a, b, i) __extension__ ({ \
> +  _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored
> \"-Wshadow\""); \
>    __m128d __a = (a); \
>    __m128d __b = (b); \
> +  _Pragma("clang diagnostic pop"); \
>    __builtin_shufflevector(__a, __b, (i) & 1, (((i) & 2) >> 1) + 2); })
>
>  static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
>
> Modified: cfe/trunk/test/Sema/warn-shadow.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-shadow.c?rev=192143&r1=192142&r2=192143&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Sema/warn-shadow.c (original)
> +++ cfe/trunk/test/Sema/warn-shadow.c Mon Oct  7 18:51:11 2013
> @@ -1,5 +1,7 @@
>  // RUN: %clang_cc1 -verify -fsyntax-only -fblocks -Wshadow %s
>
> +#include <emmintrin.h>
> +
>  int i;          // expected-note 3 {{previous declaration is here}}
>
>  void foo() {
> @@ -59,3 +61,11 @@ void rdar8883302() {
>  void test8() {
>    int bob; // expected-warning {{declaration shadows a variable in the
> global scope}}
>  }
> +
> +// Test that using two macros from emmintrin do not cause a
> +// useless -Wshadow warning.
> +void rdar10679282() {
> +  __m128i qf = _mm_setzero_si128();
> +  qf = _mm_slli_si128(_mm_add_epi64(qf, _mm_srli_si128(qf, 8)), 8); //
> no-warning
> +  (void) qf;
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> [email protected]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to