[clang] 32fffe5 - [Clang] prevent assertion on empty filename in #embed directive (#163072)

via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 13 05:53:29 PDT 2025


Author: Oleksandr T.
Date: 2025-10-13T15:53:25+03:00
New Revision: 32fffe5680d0fa3854787b95bbd2712085f611ad

URL: https://github.com/llvm/llvm-project/commit/32fffe5680d0fa3854787b95bbd2712085f611ad
DIFF: https://github.com/llvm/llvm-project/commit/32fffe5680d0fa3854787b95bbd2712085f611ad.diff

LOG: [Clang] prevent assertion on empty filename in #embed directive (#163072)

Fixes #162951

---

This PR addresses the issue of Clang asserting when processing `#embed`
with an empty filename

```c
#embed <>
```

Added: 
    clang/test/Preprocessor/embed_empty_file.c

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Lex/PPDirectives.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index dcdcde2215a55..f75f97e4d55e9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -408,6 +408,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}}


        


More information about the cfe-commits mailing list