[cfe-commits] r97498 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/warn-unused-variables.c

Chris Lattner sabre at nondot.org
Mon Mar 1 13:06:03 PST 2010


Author: lattner
Date: Mon Mar  1 15:06:03 2010
New Revision: 97498

URL: http://llvm.org/viewvc/llvm-project?rev=97498&view=rev
Log:
fix PR5933: don't warn about unused variables if a function has other errors in it.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/warn-unused-variables.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=97498&r1=97497&r2=97498&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Mar  1 15:06:03 2010
@@ -553,7 +553,8 @@
     if (!D->getDeclName()) continue;
 
     // Diagnose unused variables in this scope.
-    if (ShouldDiagnoseUnusedDecl(D))
+    if (ShouldDiagnoseUnusedDecl(D) &&
+        NumErrorsAtStartOfFunction == getDiagnostics().getNumErrors())
       Diag(D->getLocation(), diag::warn_unused_variable) << D->getDeclName();
     
     // Remove this name from our lexical scope.

Modified: cfe/trunk/test/Sema/warn-unused-variables.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-unused-variables.c?rev=97498&r1=97497&r2=97498&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-unused-variables.c (original)
+++ cfe/trunk/test/Sema/warn-unused-variables.c Mon Mar  1 15:06:03 2010
@@ -17,3 +17,9 @@
 	(void)sizeof(i);
 	return;
 }
+
+// PR5933
+int f2() {
+  int X = 4;  // Shouldn't have a bogus 'unused variable X' warning.
+  return Y + X; // expected-error {{use of undeclared identifier 'Y'}}
+}





More information about the cfe-commits mailing list