[clang] Added macro name to redifine and undef macro as a part of the issue#88882 (PR #167299)
Sai Deepak Sana via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 10 03:31:16 PST 2025
https://github.com/saideepaksana created https://github.com/llvm/llvm-project/pull/167299
For the issue #88882,
files changed `clang/include/clang/Basic/DiagnosticLexKinds.td`, `clang/lib/Lex/PPDirectives.cpp`. I tried adding %0 place holder in the .td file, so by passing the identifier info of the redefined builtin macro, so now it says clearly which macro affected, before it was `warning: redefining builtin macro` and now it is `warning: redefining builtin macro '__FILE__'`.
>From ded85b867e2e332ff23d5f7ae528b8c5a1ab82a0 Mon Sep 17 00:00:00 2001
From: Sai Deepak <deepaksana9030 at gmail.com>
Date: Mon, 10 Nov 2025 11:23:25 +0000
Subject: [PATCH] Added macro name to redifine and undef macro as a part of the
issue#88882
---
clang/include/clang/Basic/DiagnosticLexKinds.td | 2 +-
clang/lib/Lex/PPDirectives.cpp | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 417187222e448..e9339f473c67a 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -396,7 +396,7 @@ def pp_out_of_date_dependency : Warning<
"current file is older than dependency %0">;
def ext_pp_undef_builtin_macro : ExtWarn<"undefining builtin macro">,
InGroup<BuiltinMacroRedefined>;
-def ext_pp_redef_builtin_macro : ExtWarn<"redefining builtin macro">,
+def ext_pp_redef_builtin_macro : ExtWarn<"redefining builtin macro '%0'">,
InGroup<BuiltinMacroRedefined>;
def pp_disabled_macro_expansion : Warning<
"disabled expansion of recursive macro">, DefaultIgnore,
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 891c8ab7f3155..38780f4fc9a89 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -3289,7 +3289,7 @@ void Preprocessor::HandleDefineDirective(
// Warn if defining "__LINE__" and other builtins, per C99 6.10.8/4 and
// C++ [cpp.predefined]p4, but allow it as an extension.
if (isLanguageDefinedBuiltin(SourceMgr, OtherMI, II->getName()))
- Diag(MacroNameTok, diag::ext_pp_redef_builtin_macro);
+ Diag(MacroNameTok, diag::ext_pp_redef_builtin_macro) << MacroNameTok.getIdentifierInfo(); // inserting this diagonstic message into stream.
// Macros must be identical. This means all tokens and whitespace
// separation must be the same. C99 6.10.3p2.
else if (!OtherMI->isAllowRedefinitionsWithoutWarning() &&
@@ -3354,7 +3354,7 @@ void Preprocessor::HandleUndefDirective() {
// Warn if undefining "__LINE__" and other builtins, per C99 6.10.8/4 and
// C++ [cpp.predefined]p4, but allow it as an extension.
if (isLanguageDefinedBuiltin(SourceMgr, MI, II->getName()))
- Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);
+ Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro) << MacroNameTok.getIdentifierInfo(); // inserting this diagnostic message into it
if (MI->isWarnIfUnused())
WarnUnusedMacroLocs.erase(MI->getDefinitionLoc());
More information about the cfe-commits
mailing list