[clang] [clang][Lex][NFC] Reorder SrcMgr checks in CheckMacroName (PR #141483)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Tue May 27 21:55:05 PDT 2025
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/141483 at github.com>
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/141483
>From fc2a7157b912b4eff6e9921b797b01792506a72c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 26 May 2025 14:05:24 +0200
Subject: [PATCH 1/2] [clang][Lex][NFC] Reorder SrcMgr checks in CheckMacroName
isInPredefinedFile() will look at the presumed loc, which is
comparatively slow. Move it after isInSystemFile().
---
clang/lib/Lex/PPDirectives.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index b2a8459d6b9cc..12688f0939a26 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -373,8 +373,8 @@ 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)) {
+ if (!SourceMgr.isInSystemHeader(MacroNameLoc) &&
+ !SourceMgr.isInPredefinedFile(MacroNameLoc)) {
MacroDiag D = MD_NoWarn;
if (isDefineUndef == MU_Define) {
D = shouldWarnOnMacroDef(*this, II);
>From 4b6b18fb182bbeded2069651f9b13dd5a5953ce0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Wed, 28 May 2025 06:54:47 +0200
Subject: [PATCH 2/2] Add requested comment
---
clang/lib/Lex/PPDirectives.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 12688f0939a26..d4988e820e9b2 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -373,6 +373,8 @@ 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).
+ // 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;
More information about the cfe-commits
mailing list