https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/175104

>From 29781d4b9a3bbe3acfeb01fc5cad9ade03690bad Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk <[email protected]>
Date: Fri, 9 Jan 2026 03:03:53 +0200
Subject: [PATCH] [Clang] prevent assertion in __has_embed parameter recovery
 at end-of-directive

---
 clang/docs/ReleaseNotes.rst                            |  1 +
 clang/lib/Lex/PPDirectives.cpp                         |  4 ++--
 .../Preprocessor/embed___has_embed_parsing_errors.c    | 10 ++++++++++
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 932b9fad40c42..1e8b3427e2c17 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -553,6 +553,7 @@ Bug Fixes in This Version
 - Fixed a crash when parsing malformed #pragma clang loop 
vectorize_width(4,8,16)
   by diagnosing invalid comma-separated argument lists. (#GH166325)
 - Clang now treats enumeration constants of fixed-underlying enums as the 
enumerated type. (#GH172118)
+- Fixed a failed assertion in the preprocessor when ``__has_embed`` parameters 
are missing parentheses. (#GH175088)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index d17e253556697..91bcb0af400bd 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -3686,14 +3686,14 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool 
ForHasEmbed) {
           std::pair<tok::TokenKind, SourceLocation> Matches) {
         Diag(CurTok, diag::err_expected) << Expected;
         Diag(Matches.second, diag::note_matching) << Matches.first;
-        if (CurTok.isNot(EndTokenKind))
+        if (CurTok.isNot(tok::eod))
           DiscardUntilEndOfDirective(CurTok);
       };
 
   auto ExpectOrDiagAndSkipToEOD = [&](tok::TokenKind Kind) {
     if (CurTok.isNot(Kind)) {
       Diag(CurTok, diag::err_expected) << Kind;
-      if (CurTok.isNot(EndTokenKind))
+      if (CurTok.isNot(tok::eod))
         DiscardUntilEndOfDirective(CurTok);
       return false;
     }
diff --git a/clang/test/Preprocessor/embed___has_embed_parsing_errors.c 
b/clang/test/Preprocessor/embed___has_embed_parsing_errors.c
index 8ab53f6b89c0d..4c6b03069c518 100644
--- a/clang/test/Preprocessor/embed___has_embed_parsing_errors.c
+++ b/clang/test/Preprocessor/embed___has_embed_parsing_errors.c
@@ -282,3 +282,13 @@
 #if __has_embed (__FILE__ limit(1) foo
 int a = __has_embed (__FILE__);
 #endif
+
+// expected-error@+2 {{expected '('}} \
+   expected-error@+2 {{expected value in expression}}
+#if __has_embed("" if_empty
+#endif
+
+// expected-error@+2 {{expected '('}} \
+   expected-error@+2 {{expected value in expression}}
+#if __has_embed("" limit
+#endif

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

Reply via email to