https://github.com/AnonMiraj updated 
https://github.com/llvm/llvm-project/pull/237805

>From 55a467c5f3d2a5c5f6bd4a08102f0893367a5478 Mon Sep 17 00:00:00 2001
From: Anonmiraj <[email protected]>
Date: Wed, 7 Oct 2026 16:16:14 +0300
Subject: [PATCH 1/2] [clang] Check the macro name before its presumed file

---
 clang/lib/Lex/PPDirectives.cpp | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index da0098f54bd334..43fb06372c0236 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -164,21 +164,13 @@ static bool isLanguageDefinedBuiltin(const SourceManager 
&SourceMgr,
   // defined.
   if (MI->isBuiltinMacro())
     return true;
-  // Builtin macros are defined in the builtin file
-  if (!SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc()))
+  // C uses __STDC* macros; C++ uses __cplusplus and __cpp* feature macros.
+  // Others aren't language-defined. Checking names is cheaper than finding 
files.
+  if (!MacroName.starts_with("__STDC") && MacroName != "__cplusplus" &&
+      !MacroName.starts_with("__cpp"))
     return false;
-  // C defines macros starting with __STDC, and C++ defines macros starting 
with
-  // __STDCPP
-  if (MacroName.starts_with("__STDC"))
-    return true;
-  // C++ defines the __cplusplus macro
-  if (MacroName == "__cplusplus")
-    return true;
-  // C++ defines various feature-test macros starting with __cpp
-  if (MacroName.starts_with("__cpp"))
-    return true;
-  // Anything else isn't language-defined
-  return false;
+  // Builtin macros are defined in the builtin file
+  return SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc());
 }
 
 static bool isReservedCXXAttributeName(Preprocessor &PP, IdentifierInfo *II) {

>From 83214f7b7af487ac4a509ce83280bb212452d30d Mon Sep 17 00:00:00 2001
From: Anonmiraj <[email protected]>
Date: Mon, 2 Nov 2026 02:55:36 +0200
Subject: [PATCH 2/2] fix formatting

---
 clang/lib/Lex/PPDirectives.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 43fb06372c0236..c4a5f664083f1a 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -165,7 +165,8 @@ static bool isLanguageDefinedBuiltin(const SourceManager 
&SourceMgr,
   if (MI->isBuiltinMacro())
     return true;
   // C uses __STDC* macros; C++ uses __cplusplus and __cpp* feature macros.
-  // Others aren't language-defined. Checking names is cheaper than finding 
files.
+  // Others aren't language-defined. Checking names is cheaper than finding
+  // files.
   if (!MacroName.starts_with("__STDC") && MacroName != "__cplusplus" &&
       !MacroName.starts_with("__cpp"))
     return false;

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to