-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Added macro name to redifine and undef macro as a part of the issue#88882 #167299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-clang Author: Sai Deepak Sana (saideepaksana) ChangesFor the issue #88882, Full diff: https://github.com/llvm/llvm-project/pull/167299.diff 2 Files Affected:
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());
|
|
Thank you for your patch! Did you run regression tests locally to ensure that this patch doesn't break anything? |
You can test this locally with the following command:git-clang-format --diff origin/main HEAD --extensions cpp -- clang/lib/Lex/PPDirectives.cpp --diff_from_common_commit
View the diff from clang-format here.diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 38780f4fc..88448f9b3 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -3289,7 +3289,9 @@ 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) << MacroNameTok.getIdentifierInfo(); // inserting this diagonstic message into stream.
+ 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 +3356,9 @@ 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) << MacroNameTok.getIdentifierInfo(); // inserting this diagnostic message into it
+ Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro)
+ << MacroNameTok.getIdentifierInfo(); // inserting this diagnostic
+ // message into it
if (MI->isWarnIfUnused())
WarnUnusedMacroLocs.erase(MI->getDefinitionLoc());
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use this syntax to reference the issue fixed by this patch.
Please update tests in "clang/test/" to verify that macros appear in diagnostic messages.
Please add a release note entry to "clang/docs/ReleaseNotes.rst".
| // 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary comment. Ditto below.
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 waswarning: redefining builtin macroand now it iswarning: redefining builtin macro '__FILE__'.