summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/warn-unused-variables.c
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-03-01 23:15:13 +0000
committerDouglas Gregor <dgregor@apple.com>2010-03-01 23:15:13 +0000
commit9a28e84b325851310ca2cdfa59d8d8f2875d5a2e (patch)
tree0e7941cd59e926d8b6f66030016fecab0896c1df /clang/test/Sema/warn-unused-variables.c
parent3144e663778be58a6e378e642cef0136dface777 (diff)
downloadbcm5719-llvm-9a28e84b325851310ca2cdfa59d8d8f2875d5a2e.tar.gz
bcm5719-llvm-9a28e84b325851310ca2cdfa59d8d8f2875d5a2e.zip
Keep an explicit stack of function and block scopes, each element of
which has the label map, switch statement stack, etc. Previously, we had a single set of maps in Sema (for the function) along with a stack of block scopes. However, this lead to funky behavior with nested functions, e.g., in the member functions of local classes. The explicit-stack approach is far cleaner, and we retain a 1-element cache so that we're not malloc/free'ing every time we enter a function. Fixes PR6382. Also, tweaked the unused-variable warning suppression logic to look at errors within a given Scope rather than within a given function. The prior code wasn't looking at the right number-of-errors count when dealing with blocks, since the block's count would be deallocated before we got to ActOnPopScope. This approach works with nested blocks/functions, and gives tighter error recovery. llvm-svn: 97518
Diffstat (limited to 'clang/test/Sema/warn-unused-variables.c')
-rw-r--r--clang/test/Sema/warn-unused-variables.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/clang/test/Sema/warn-unused-variables.c b/clang/test/Sema/warn-unused-variables.c
index 4d1cde7067e..58e52b171da 100644
--- a/clang/test/Sema/warn-unused-variables.c
+++ b/clang/test/Sema/warn-unused-variables.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -fblocks -verify %s
struct s0 {
unsigned int i;
@@ -23,3 +23,10 @@ int f2() {
int X = 4; // Shouldn't have a bogus 'unused variable X' warning.
return Y + X; // expected-error {{use of undeclared identifier 'Y'}}
}
+
+int f3() {
+ int X1 = 4;
+ (void)(Y1 + X1); // expected-error {{use of undeclared identifier 'Y1'}}
+ (void)(^() { int X = 4; }); // expected-warning{{unused}}
+ (void)(^() { int X = 4; return Y + X; }); // expected-error {{use of undeclared identifier 'Y'}}
+}
OpenPOWER on IntegriCloud