diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 65b086caf3652..9d2a055b21994 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -405,6 +405,7 @@ Bug Fixes in This Version 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) +- Fixed a failed assertion with empty filename in ``#embed`` directive. (#GH162951) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 360593d0f33df..5c6ecdbc304d6 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -3991,9 +3991,12 @@ void Preprocessor::HandleEmbedDirective(SourceLocation HashLoc, Token &EmbedTok, StringRef OriginalFilename = Filename; bool isAngled = GetIncludeFilenameSpelling(FilenameTok.getLocation(), Filename); + // If GetIncludeFilenameSpelling set the start ptr to null, there was an // error. - assert(!Filename.empty()); + if (Filename.empty()) + return; + OptionalFileEntryRef MaybeFileRef = this->LookupEmbedFile(Filename, isAngled, true, LookupFromFile); if (!MaybeFileRef) { diff --git a/clang/test/Preprocessor/embed_empty_file.c b/clang/test/Preprocessor/embed_empty_file.c new file mode 100644 index 0000000000000..5ad807e80a36e --- /dev/null +++ b/clang/test/Preprocessor/embed_empty_file.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -std=c23 %s -E -verify + +#embed <> // expected-error {{empty filename}} +#embed "" // expected-error {{empty filename}}