-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[Clang] Do not warn for serialized builtin or command-line definitions #137306
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
[Clang] Do not warn for serialized builtin or command-line definitions #137306
Conversation
…d-line definitions
When using -dD to generte a preprocessed output, the #define directives are preserved. This includes builtin and command line definitions. Before, clang would warn for reserved identifiers for serialzied builtin and command-line definitions. This patch adds an exception to these cases.
@llvm/pr-subscribers-clang Author: Juan Manuel Martinez Caamaño (jmmartinez) ChangesWhen using Before, clang would warn for reserved identifiers for serialized built-in Full diff: https://github.com/llvm/llvm-project/pull/137306.diff 2 Files Affected:
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 6c337801a8435..6468e62889413 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -371,8 +371,12 @@ bool Preprocessor::CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef,
SourceLocation MacroNameLoc = MacroNameTok.getLocation();
if (ShadowFlag)
*ShadowFlag = false;
- if (!SourceMgr.isInSystemHeader(MacroNameLoc) &&
- (SourceMgr.getBufferName(MacroNameLoc) != "<built-in>")) {
+ // 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).
+ bool IsBuiltinOrCmd = SourceMgr.isWrittenInBuiltinFile(MacroNameLoc) ||
+ SourceMgr.isWrittenInCommandLineFile(MacroNameLoc);
+ if (!IsBuiltinOrCmd && !SourceMgr.isInSystemHeader(MacroNameLoc)) {
MacroDiag D = MD_NoWarn;
if (isDefineUndef == MU_Define) {
D = shouldWarnOnMacroDef(*this, II);
diff --git a/clang/test/Preprocessor/macro_reserved.i b/clang/test/Preprocessor/macro_reserved.i
new file mode 100644
index 0000000000000..c9ed044e4c931
--- /dev/null
+++ b/clang/test/Preprocessor/macro_reserved.i
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -x cpp-output %s
+#pragma clang diagnostic push
+#pragma clang diagnostic warning "-Wreserved-macro-identifier"
+# 1 "<built-in>" 1
+#define __BUILTIN__
+# 2 "<command line>" 1
+#define __CMD__
+# 3 "biz.cpp" 1
+#define __SOME_FILE__ // expected-warning {{macro name is a reserved identifier}}
+int v;
+#pragma clang diagnostic pop
|
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.
LGTM, thanks!
Thanks ! |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/197/builds/4754 Here is the relevant piece of the build log for the reference
|
This has a large negative compile-time impact, esp for unoptimized builds: https://llvm-compile-time-tracker.com/compare.php?from=7ec1e0f7ba9f3b03fa6163ab62c17dc9b404303e&to=0d3d2f639c42b22fc1b9453c7b834dbb0f16c0dc&stat=instructions:u |
// through the command line (the later may be present if -dD was used to | ||
// generate the preprocessed file). | ||
bool IsBuiltinOrCmd = SourceMgr.isWrittenInBuiltinFile(MacroNameLoc) || | ||
SourceMgr.isWrittenInCommandLineFile(MacroNameLoc); |
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.
Can at least combine these to avoid the duplicate getPresumedLoc(), but possibly these can be more efficient in general? E.g. isInSystemHeader has a much more optimized implementation.
@jmmartinez Ping. |
llvm#137306) When using `-dD` to generate a preprocessed output, the `#define` directives are preserved. This includes built-in and command-line definitions. Before, clang would warn for reserved identifiers for serialized built-in and command-line definitions. This patch adds an exception to these cases.
Yeah, those perf drops are pretty unfortunate. Nikita's idea of trying to combine the checks makes sense to me as a good approach to try. |
llvm#137306) When using `-dD` to generate a preprocessed output, the `#define` directives are preserved. This includes built-in and command-line definitions. Before, clang would warn for reserved identifiers for serialized built-in and command-line definitions. This patch adds an exception to these cases.
llvm#137306) When using `-dD` to generate a preprocessed output, the `#define` directives are preserved. This includes built-in and command-line definitions. Before, clang would warn for reserved identifiers for serialized built-in and command-line definitions. This patch adds an exception to these cases.
llvm#137306) When using `-dD` to generate a preprocessed output, the `#define` directives are preserved. This includes built-in and command-line definitions. Before, clang would warn for reserved identifiers for serialized built-in and command-line definitions. This patch adds an exception to these cases.
When using
-dD
to generate a preprocessed output, the#define
directivesare preserved. This includes built-in and command-line definitions.
Before, clang would warn for reserved identifiers for serialized built-in
and command-line definitions.
This patch adds an exception to these cases.