[clang] [clang] [NFC] Skip macro source-location check for names that can't warn (PR #208862)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 10 17:11:25 PDT 2026
https://github.com/AnonMiraj updated https://github.com/llvm/llvm-project/pull/208862
>From fcf318165e95224d26c37b0da81f1c6bb0f6399c Mon Sep 17 00:00:00 2001
From: Anonmiraj <ezzibrahimx at gmail.com>
Date: Sat, 11 Jul 2026 02:51:32 +0300
Subject: [PATCH 1/2] [clang] Skip macro source-location check for names that
can't warn
---
clang/lib/Lex/PPDirectives.cpp | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index eb21a510dcf83..0323743ad9b20 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -396,16 +396,16 @@ 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) &&
+ // NB: isInPredefinedFile() (via getPresumedLoc) is relatively expensive, so
+ // only run it for names that can actually warn.
+ MacroDiag D = MD_NoWarn;
+ if (isDefineUndef == MU_Define) {
+ D = shouldWarnOnMacroDef(*this, II);
+ }
+ else if (isDefineUndef == MU_Undef)
+ D = shouldWarnOnMacroUndef(*this, II);
+ if (D != MD_NoWarn && !SourceMgr.isInSystemHeader(MacroNameLoc) &&
!SourceMgr.isInPredefinedFile(MacroNameLoc)) {
- MacroDiag D = MD_NoWarn;
- if (isDefineUndef == MU_Define) {
- D = shouldWarnOnMacroDef(*this, II);
- }
- else if (isDefineUndef == MU_Undef)
- D = shouldWarnOnMacroUndef(*this, II);
if (D == MD_KeywordDef) {
// We do not want to warn on some patterns widely used in configuration
// scripts. This requires analyzing next tokens, so do not issue warnings
>From c4093a81e10cc2976ca179bb478e0a407778e38e Mon Sep 17 00:00:00 2001
From: Anonmiraj <ezzibrahimx at gmail.com>
Date: Sat, 11 Jul 2026 03:11:11 +0300
Subject: [PATCH 2/2] fix formatting
---
clang/lib/Lex/PPDirectives.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 0323743ad9b20..402b3f43d7fb9 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -401,8 +401,7 @@ bool Preprocessor::CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef,
MacroDiag D = MD_NoWarn;
if (isDefineUndef == MU_Define) {
D = shouldWarnOnMacroDef(*this, II);
- }
- else if (isDefineUndef == MU_Undef)
+ } else if (isDefineUndef == MU_Undef)
D = shouldWarnOnMacroUndef(*this, II);
if (D != MD_NoWarn && !SourceMgr.isInSystemHeader(MacroNameLoc) &&
!SourceMgr.isInPredefinedFile(MacroNameLoc)) {
More information about the cfe-commits
mailing list