https://github.com/c-rhodes updated https://github.com/llvm/llvm-project/pull/178193
>From bda27d51e2086a120e37a3f228f46d79cb0e4774 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk <[email protected]> Date: Mon, 26 Jan 2026 14:39:09 +0200 Subject: [PATCH] [Clang] prevent assertion in __has_embed parameter recovery at end-of-directive (#175104) Fixes #175088 --- This PR addresses an assertion failure in the preprocessor triggered when `__has_embed` parameter parsing reaches end-of-directive while expecting a parenthesized argument. --- 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 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@+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 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
