[clang] 5a7931f - [clang][Lex][NFC] Reorder SrcMgr checks in CheckMacroName (#141483)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 29 07:07:47 PDT 2025
Author: Timm Baeder
Date: 2025-05-29T16:07:44+02:00
New Revision: 5a7931f04d627909a70bbc1b5566cc6c69d26860
URL: https://github.com/llvm/llvm-project/commit/5a7931f04d627909a70bbc1b5566cc6c69d26860
DIFF: https://github.com/llvm/llvm-project/commit/5a7931f04d627909a70bbc1b5566cc6c69d26860.diff
LOG: [clang][Lex][NFC] Reorder SrcMgr checks in CheckMacroName (#141483)
isInPredefinedFile() will look at the presumed loc, which is
comparatively slow. Move it after isInSystemFile().
http://llvm-compile-time-tracker.com/compare.php?from=843e362318e884991e517a54446b4faeacdad789&to=de0421a1a38052042721a67a6094f5cb38431f26&stat=instructions:u
Added:
Modified:
clang/lib/Lex/PPDirectives.cpp
Removed:
################################################################################
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 68f9ca9cb4d40..04a30f66fb736 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -373,8 +373,10 @@ bool Preprocessor::CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef,
// Macro names with reserved identifiers are accepted if built-in or passed
// through the command line (the later may be present if -dD was used to
// generate the preprocessed file).
- if (!SourceMgr.isInPredefinedFile(MacroNameLoc) &&
- !SourceMgr.isInSystemHeader(MacroNameLoc)) {
+ // NB: isInPredefinedFile() is relatively expensive, so keep it at the end
+ // of the condition.
+ if (!SourceMgr.isInSystemHeader(MacroNameLoc) &&
+ !SourceMgr.isInPredefinedFile(MacroNameLoc)) {
MacroDiag D = MD_NoWarn;
if (isDefineUndef == MU_Define) {
D = shouldWarnOnMacroDef(*this, II);
More information about the cfe-commits
mailing list