[clang] [Clang] Do not warn for serialized builtin or command-line definitions (PR #137306)

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Thu May 1 03:50:38 PDT 2025


Juan Manuel Martinez =?utf-8?q?CaamaƱo?= <juamarti at amd.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/137306 at github.com>


================
@@ -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);
----------------
nikic wrote:

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.

https://github.com/llvm/llvm-project/pull/137306


More information about the cfe-commits mailing list