diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6daf2ab23bbf2..fb429a675476d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -366,6 +366,7 @@ Bug Fixes in This Version - Fixed an assertion when an improper use of the ``malloc`` attribute targeting a function without arguments caused us to try to access a non-existent argument. (#GH159080) +- Fixed a failed assertion with empty filename arguments in ``__has_embed``. (#GH159898) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index 6f12ac80d677e..dec1956ea0f9a 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -1282,11 +1282,13 @@ EmbedResult Preprocessor::EvaluateHasEmbed(Token &Tok, IdentifierInfo *II) { SmallString<128> FilenameBuffer; StringRef Filename = this->getSpelling(FilenameTok, FilenameBuffer); + if (Filename.empty()) + return EmbedResult::Empty; + bool isAngled = this->GetIncludeFilenameSpelling(FilenameTok.getLocation(), Filename); // If GetIncludeFilenameSpelling set the start ptr to null, there was an // error. - assert(!Filename.empty()); const FileEntry *LookupFromFile = this->getCurrentFileLexer() ? *this->getCurrentFileLexer()->getFileEntry() : static_cast(nullptr); diff --git a/clang/test/Preprocessor/embed___has_embed_parsing_errors.c b/clang/test/Preprocessor/embed___has_embed_parsing_errors.c index 0591c595253bc..9c512a4882e2d 100644 --- a/clang/test/Preprocessor/embed___has_embed_parsing_errors.c +++ b/clang/test/Preprocessor/embed___has_embed_parsing_errors.c @@ -247,3 +247,6 @@ expected-error@+2 {{expected value in expression}} #if __has_embed (__FILE__ limit(-100000000000000000)) != __STDC_EMBED_NOT_FOUND__ #endif + +#if __has_embed("") // expected-error {{empty filename}} +#endif