xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/pragma-unused.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -Wunused-parameter -Wused-but-marked-unused -Wunused -verify %s
2*f4a2713aSLionel Sambuc 
f1(void)3*f4a2713aSLionel Sambuc void f1(void) {
4*f4a2713aSLionel Sambuc   int x, y, z;
5*f4a2713aSLionel Sambuc   #pragma unused(x)
6*f4a2713aSLionel Sambuc   #pragma unused(y, z)
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc   int w; // expected-warning {{unused}}
9*f4a2713aSLionel Sambuc   #pragma unused w // expected-warning{{missing '(' after '#pragma unused' - ignoring}}
10*f4a2713aSLionel Sambuc }
11*f4a2713aSLionel Sambuc 
f2(void)12*f4a2713aSLionel Sambuc void f2(void) {
13*f4a2713aSLionel Sambuc   int x, y; // expected-warning {{unused}} expected-warning {{unused}}
14*f4a2713aSLionel Sambuc   #pragma unused(x,) // expected-warning{{expected '#pragma unused' argument to be a variable name}}
15*f4a2713aSLionel Sambuc   #pragma unused() // expected-warning{{expected '#pragma unused' argument to be a variable name}}
16*f4a2713aSLionel Sambuc }
17*f4a2713aSLionel Sambuc 
f3(void)18*f4a2713aSLionel Sambuc void f3(void) {
19*f4a2713aSLionel Sambuc   #pragma unused(x) // expected-warning{{undeclared variable 'x' used as an argument for '#pragma unused'}}
20*f4a2713aSLionel Sambuc }
21*f4a2713aSLionel Sambuc 
f4(void)22*f4a2713aSLionel Sambuc void f4(void) {
23*f4a2713aSLionel Sambuc   int w; // expected-warning {{unused}}
24*f4a2713aSLionel Sambuc   #pragma unused((w)) // expected-warning{{expected '#pragma unused' argument to be a variable name}}
25*f4a2713aSLionel Sambuc }
26*f4a2713aSLionel Sambuc 
f6(void)27*f4a2713aSLionel Sambuc void f6(void) {
28*f4a2713aSLionel Sambuc   int z; // no-warning
29*f4a2713aSLionel Sambuc   {
30*f4a2713aSLionel Sambuc     #pragma unused(z) // no-warning
31*f4a2713aSLionel Sambuc   }
32*f4a2713aSLionel Sambuc }
33*f4a2713aSLionel Sambuc 
f7()34*f4a2713aSLionel Sambuc void f7() {
35*f4a2713aSLionel Sambuc   int y;
36*f4a2713aSLionel Sambuc   #pragma unused(undeclared, undefined, y) // expected-warning{{undeclared variable 'undeclared' used as an argument for '#pragma unused'}} expected-warning{{undeclared variable 'undefined' used as an argument for '#pragma unused'}}
37*f4a2713aSLionel Sambuc }
38*f4a2713aSLionel Sambuc 
f8(int x)39*f4a2713aSLionel Sambuc int f8(int x) { // expected-warning{{unused parameter 'x'}}
40*f4a2713aSLionel Sambuc   return 0;
41*f4a2713aSLionel Sambuc }
42*f4a2713aSLionel Sambuc 
f9(int x)43*f4a2713aSLionel Sambuc int f9(int x) {
44*f4a2713aSLionel Sambuc   return x;
45*f4a2713aSLionel Sambuc }
46*f4a2713aSLionel Sambuc 
f10(int x)47*f4a2713aSLionel Sambuc int f10(int x) {
48*f4a2713aSLionel Sambuc   #pragma unused(x)
49*f4a2713aSLionel Sambuc   return 0;
50*f4a2713aSLionel Sambuc }
51*f4a2713aSLionel Sambuc 
f11(int x)52*f4a2713aSLionel Sambuc int f11(int x) {
53*f4a2713aSLionel Sambuc   #pragma unused(x)
54*f4a2713aSLionel Sambuc   return x; // expected-warning{{'x' was marked unused but was used}}
55*f4a2713aSLionel Sambuc }
56*f4a2713aSLionel Sambuc 
f12(int x)57*f4a2713aSLionel Sambuc int f12(int x) {
58*f4a2713aSLionel Sambuc   int y = x;
59*f4a2713aSLionel Sambuc   #pragma unused(x) // expected-warning{{'x' was marked unused but was used}}
60*f4a2713aSLionel Sambuc   return y;
61*f4a2713aSLionel Sambuc }
62*f4a2713aSLionel Sambuc 
63*f4a2713aSLionel Sambuc // rdar://8793832
64*f4a2713aSLionel Sambuc static int glob_var = 0;
65*f4a2713aSLionel Sambuc #pragma unused(glob_var)
66