From: Chris Lattner Date: Fri, 16 Jan 2009 19:50:11 +0000 (+0000) Subject: As a performance optimization, don't bother calling MacroInfo::isIdenticalTo X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=41c3ae108a54437f27fa99ddcb9bafcf113bde80;p=clang As a performance optimization, don't bother calling MacroInfo::isIdenticalTo if warnings in system headers are disabled. isIdenticalTo can end up calling the expensive getSpelling method, and other bad stuff and is completely unneeded if the warning will be discarded anyway. rdar://6502956 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62347 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index a5684cc36a..0566ec54b0 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -1060,16 +1060,23 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) { // Finally, if this identifier already had a macro defined for it, verify that // the macro bodies are identical and free the old definition. if (MacroInfo *OtherMI = getMacroInfo(MacroNameTok.getIdentifierInfo())) { - if (!OtherMI->isUsed()) - Diag(OtherMI->getDefinitionLoc(), diag::pp_macro_not_used); - - // Macros must be identical. This means all tokes and whitespace separation - // must be the same. C99 6.10.3.2. - if (!MI->isIdenticalTo(*OtherMI, *this)) { - Diag(MI->getDefinitionLoc(), diag::ext_pp_macro_redef) - << MacroNameTok.getIdentifierInfo(); - Diag(OtherMI->getDefinitionLoc(), diag::note_previous_definition); + // It is very common for system headers to have tons of macro redefinitions + // and for warnings to be disabled in system headers. If this is the case, + // then don't bother calling MacroInfo::isIdenticalTo. + if (!Diags.getSuppressSystemWarnings() || + !SourceMgr.isInSystemHeader(DefineTok.getLocation())) { + if (!OtherMI->isUsed()) + Diag(OtherMI->getDefinitionLoc(), diag::pp_macro_not_used); + + // Macros must be identical. This means all tokes and whitespace + // separation must be the same. C99 6.10.3.2. + if (!MI->isIdenticalTo(*OtherMI, *this)) { + Diag(MI->getDefinitionLoc(), diag::ext_pp_macro_redef) + << MacroNameTok.getIdentifierInfo(); + Diag(OtherMI->getDefinitionLoc(), diag::note_previous_definition); + } } + ReleaseMacroInfo(OtherMI); }