Make #pragma unused work for static local variables.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118500 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaAttr.cpp b/lib/Sema/SemaAttr.cpp
index d7290c3..02b8289 100644
--- a/lib/Sema/SemaAttr.cpp
+++ b/lib/Sema/SemaAttr.cpp
@@ -282,7 +282,7 @@
}
VarDecl *VD = Lookup.getAsSingle<VarDecl>();
- if (!VD || !VD->hasLocalStorage()) {
+ if (!VD || !(VD->hasLocalStorage() || VD->isStaticLocal())) {
Diag(PragmaLoc, diag::warn_pragma_unused_expected_localvar)
<< Name << SourceRange(Tok.getLocation());
continue;
diff --git a/test/SemaCXX/warn-unused-variables.cpp b/test/SemaCXX/warn-unused-variables.cpp
index 6992cdc..8ae7d6a 100644
--- a/test/SemaCXX/warn-unused-variables.cpp
+++ b/test/SemaCXX/warn-unused-variables.cpp
@@ -59,3 +59,9 @@
X<char> str (read_from_file()); // expected-error{{use of undeclared identifier 'read_from_file'}}
}
}
+
+void unused_local_static() {
+ static int x = 0;
+ static int y = 0; // expected-warning{{unused variable 'y'}}
+#pragma unused(x)
+}