[llvm-branch-commits] [clang] release/22.x: [Clang] prevent assertion in __has_embed parameter recovery at end-of-directive (PR #178193)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jan 27 04:47:20 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Oleksandr Tarasiuk (a-tarasyuk)
<details>
<summary>Changes</summary>
Manual backport of 1d316ef4ba71d843f1e49f86e831dbf8c64ebd83
---
Full diff: https://github.com/llvm/llvm-project/pull/178193.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.rst (+1)
- (modified) clang/lib/Lex/PPDirectives.cpp (+2-2)
- (modified) clang/test/Preprocessor/embed___has_embed_parsing_errors.c (+10)
``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 52c7c0466e87d..a01339cfb7b57 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -571,6 +571,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 at +2 {{expected '('}} \
+ expected-error at +2 {{expected value in expression}}
+#if __has_embed("" if_empty
+#endif
+
+// expected-error at +2 {{expected '('}} \
+ expected-error at +2 {{expected value in expression}}
+#if __has_embed("" limit
+#endif
``````````
</details>
https://github.com/llvm/llvm-project/pull/178193
More information about the llvm-branch-commits
mailing list