summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2010-10-22 23:37:08 +0000
committerAnders Carlsson <andersca@mac.com>2010-10-22 23:37:08 +0000
commit73067a02db9aa1e29d6df0bece45f8b5f390ed57 (patch)
treeaa47d17dddf91395218071a23fa460f2cded73a2 /clang/test/Sema
parent9ef5c507cea5b8abf0b202d20d67245856c94acc (diff)
downloadbcm5719-llvm-73067a02db9aa1e29d6df0bece45f8b5f390ed57.tar.gz
bcm5719-llvm-73067a02db9aa1e29d6df0bece45f8b5f390ed57.zip
Warn if a variable marked with the "unused" attribute is used. Patch by Darin Adler!
llvm-svn: 117184
Diffstat (limited to 'clang/test/Sema')
-rw-r--r--clang/test/Sema/attr-unused.c22
-rw-r--r--clang/test/Sema/pragma-unused.c25
2 files changed, 43 insertions, 4 deletions
diff --git a/clang/test/Sema/attr-unused.c b/clang/test/Sema/attr-unused.c
index 28715141b99..795b0831233 100644
--- a/clang/test/Sema/attr-unused.c
+++ b/clang/test/Sema/attr-unused.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify -Wunused-variable -fsyntax-only %s
+// RUN: %clang_cc1 -verify -Wunused -Wunused-parameter -Wunused -fsyntax-only %s
static void (*fp0)(void) __attribute__((unused));
@@ -20,8 +20,24 @@ void test0() {
int x; // expected-warning {{unused variable}}
Int_not_unused i0; // expected-warning {{unused variable}}
- Int_unused i1;
+ Int_unused i1; // expected-warning {{'Int_unused' was marked unused but was used}}
struct Test0_not_unused s0; // expected-warning {{unused variable}}
- struct Test0_unused s1;
+ struct Test0_unused s1; // expected-warning {{'Test0_unused' was marked unused but was used}}
+}
+
+int f3(int x) { // expected-warning{{unused parameter 'x'}}
+ return 0;
+}
+
+int f4(int x) {
+ return x;
+}
+
+int f5(int x __attribute__((__unused__))) {
+ return 0;
+}
+
+int f6(int x __attribute__((__unused__))) {
+ return x; // expected-warning{{'x' was marked unused but was used}}
}
diff --git a/clang/test/Sema/pragma-unused.c b/clang/test/Sema/pragma-unused.c
index 8a051a3ec9e..272f3a2f380 100644
--- a/clang/test/Sema/pragma-unused.c
+++ b/clang/test/Sema/pragma-unused.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-parameter -verify %s
void f1(void) {
int x, y, z;
@@ -41,3 +41,26 @@ void f7() {
#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'}}
}
+int f8(int x) { // expected-warning{{unused parameter 'x'}}
+ return 0;
+}
+
+int f9(int x) {
+ return x;
+}
+
+int f10(int x) {
+ #pragma unused(x)
+ return 0;
+}
+
+int f11(int x) {
+ #pragma unused(x)
+ return x; // expected-warning{{'x' was marked unused but was used}}
+}
+
+int f12(int x) {
+ int y = x;
+ #pragma unused(x) // expected-warning{{'x' was marked unused but was used}}
+ return y;
+}
OpenPOWER on IntegriCloud