xref: /llvm-project/clang/test/Sema/warn-shadow.c (revision 854cc293a70bba6c613600bd72dba6c7ba33e6de)
1 // RUN: %clang_cc1 -verify -fsyntax-only -fblocks -Wshadow %s
2 
3 #include <emmintrin.h>
4 
5 int i;          // expected-note 3 {{previous declaration is here}}
6 
7 void foo() {
8   int pass1;
9   int i;        // expected-warning {{declaration shadows a variable in the global scope}} \
10                 // expected-note {{previous declaration is here}}
11   {
12     int pass2;
13     int i;      // expected-warning {{declaration shadows a local variable}} \
14                 // expected-note {{previous declaration is here}}
15     {
16       int pass3;
17       int i;    // expected-warning {{declaration shadows a local variable}}
18     }
19   }
20 
21   int sin; // okay; 'sin' has not been declared, even though it's a builtin.
22 }
23 
24 // <rdar://problem/7677531>
25 void (^test1)(int) = ^(int i) { // expected-warning {{declaration shadows a variable in the global scope}} \
26                                  // expected-note{{previous declaration is here}}
27   {
28     int i; // expected-warning {{declaration shadows a local variable}} \
29            // expected-note{{previous declaration is here}}
30 
31     (^(int i) { return i; })(i); //expected-warning {{declaration shadows a local variable}}
32   }
33 };
34 
35 
36 struct test2 {
37   int i;
38 };
39 
40 void test3(void) {
41   struct test4 {
42     int i;
43   };
44 }
45 
46 void test4(int i) { // expected-warning {{declaration shadows a variable in the global scope}}
47 }
48 
49 // Don't warn about shadowing for function declarations.
50 void test5(int i);
51 void test6(void (*f)(int i)) {}
52 void test7(void *context, void (*callback)(void *context)) {}
53 
54 extern int bob; // expected-note {{previous declaration is here}}
55 
56 // rdar://8883302
57 void rdar8883302() {
58   extern int bob; // don't warn for shadowing.
59 }
60 
61 void test8() {
62   int bob; // expected-warning {{declaration shadows a variable in the global scope}}
63 }
64 
65 // Test that using two macros from emmintrin do not cause a
66 // useless -Wshadow warning.
67 void rdar10679282() {
68   __m128i qf = _mm_setzero_si128();
69   qf = _mm_slli_si128(_mm_add_epi64(qf, _mm_srli_si128(qf, 8)), 8); // no-warning
70   (void) qf;
71 }
72