From: Douglas Gregor Date: Wed, 7 Apr 2010 20:29:57 +0000 (+0000) Subject: Return early from Sema::MarkDeclarationReferenced when we know there X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fc2ca56874e1c8186ac30c0c3af13dc5e806cf74;p=clang Return early from Sema::MarkDeclarationReferenced when we know there 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%. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100686 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index c93acf6946..a6bcc4375e 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -843,6 +843,10 @@ public: /// ParmVarDecl pointers. template 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()) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 7967a342a2..b78e8b5b67 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -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(D) || - (isa(D) && D->getDeclContext()->isFunctionOrMethod())) + (isa(D) && D->getDeclContext()->isFunctionOrMethod())) { D->setUsed(true); - + return; + } + + if (!isa(D) && !isa(D)) + return; + // Do not mark anything as "used" within a dependent context; wait for // an instantiation. if (CurContext->isDependentContext())