]> granicus.if.org Git - clang/commitdiff
Return early from Sema::MarkDeclarationReferenced when we know there
authorDouglas Gregor <dgregor@apple.com>
Wed, 7 Apr 2010 20:29:57 +0000 (20:29 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 7 Apr 2010 20:29:57 +0000 (20:29 +0000)
isn't any extra work to perform. Also, don't check for unused
parameters when the warnings will be suppressed anyway. Improves
performance of -fsyntax-only on 403.gcc's combine.c by ~2.5%.
<rdar://problem/7836787>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100686 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaExpr.cpp

index c93acf69461e8723dbf98ab0b18764d7a1a9c97b..a6bcc4375e42bc3210475fbdbfd47bb24f1da434 100644 (file)
@@ -843,6 +843,10 @@ public:
   /// ParmVarDecl pointers.
   template<typename InputIterator>
   void DiagnoseUnusedParameters(InputIterator Param, InputIterator ParamEnd) {
+    if (Diags.getDiagnosticLevel(diag::warn_unused_parameter) == 
+          Diagnostic::Ignored)
+      return;
+    
     for (; Param != ParamEnd; ++Param) {
       if (!(*Param)->isUsed() && (*Param)->getDeclName() &&
           !(*Param)->template hasAttr<UnusedAttr>())
index 7967a342a254cf40d40254deb9cd6c3eee77683e..b78e8b5b67b8b7b1b97d294b98b872f4ee29a279 100644 (file)
@@ -7311,9 +7311,14 @@ void Sema::MarkDeclarationReferenced(SourceLocation Loc, Decl *D) {
   // (e.g. (void)sizeof()) constitute a use for warning purposes (-Wunused-variables and
   // -Wunused-parameters)
   if (isa<ParmVarDecl>(D) ||
-      (isa<VarDecl>(D) && D->getDeclContext()->isFunctionOrMethod()))
+      (isa<VarDecl>(D) && D->getDeclContext()->isFunctionOrMethod())) {
     D->setUsed(true);
-
+    return;
+  }
+  
+  if (!isa<VarDecl>(D) && !isa<FunctionDecl>(D))
+    return;
+  
   // Do not mark anything as "used" within a dependent context; wait for
   // an instantiation.
   if (CurContext->isDependentContext())