Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0d3d2f6

Browse files
authored
[Clang] Do not warn for serialized builtin or command-line definitions (#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.
1 parent 7ec1e0f commit 0d3d2f6

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

clang/lib/Lex/PPDirectives.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,12 @@ bool Preprocessor::CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef,
371371
SourceLocation MacroNameLoc = MacroNameTok.getLocation();
372372
if (ShadowFlag)
373373
*ShadowFlag = false;
374-
if (!SourceMgr.isInSystemHeader(MacroNameLoc) &&
375-
(SourceMgr.getBufferName(MacroNameLoc) != "<built-in>")) {
374+
// Macro names with reserved identifiers are accepted if built-in or passed
375+
// through the command line (the later may be present if -dD was used to
376+
// generate the preprocessed file).
377+
bool IsBuiltinOrCmd = SourceMgr.isWrittenInBuiltinFile(MacroNameLoc) ||
378+
SourceMgr.isWrittenInCommandLineFile(MacroNameLoc);
379+
if (!IsBuiltinOrCmd && !SourceMgr.isInSystemHeader(MacroNameLoc)) {
376380
MacroDiag D = MD_NoWarn;
377381
if (isDefineUndef == MU_Define) {
378382
D = shouldWarnOnMacroDef(*this, II);
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify -x cpp-output %s
2+
#pragma clang diagnostic push
3+
#pragma clang diagnostic warning "-Wreserved-macro-identifier"
4+
# 1 "<built-in>" 1
5+
#define __BUILTIN__
6+
# 2 "<command line>" 1
7+
#define __CMD__
8+
# 3 "biz.cpp" 1
9+
#define __SOME_FILE__ // expected-warning {{macro name is a reserved identifier}}
10+
int v;
11+
#pragma clang diagnostic pop

0 commit comments

Comments
 (0)