Skip to content

Commit 32fffe5

Browse files
authored
[Clang] prevent assertion on empty filename in #embed directive (llvm#163072)
Fixes llvm#162951 --- This PR addresses the issue of Clang asserting when processing `#embed` with an empty filename ```c #embed <> ```
1 parent 8a27b48 commit 32fffe5

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ Bug Fixes in This Version
408408
a function without arguments caused us to try to access a non-existent argument.
409409
(#GH159080)
410410
- Fixed a failed assertion with empty filename arguments in ``__has_embed``. (#GH159898)
411+
- Fixed a failed assertion with empty filename in ``#embed`` directive. (#GH162951)
411412

412413
Bug Fixes to Compiler Builtins
413414
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Lex/PPDirectives.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3991,9 +3991,12 @@ void Preprocessor::HandleEmbedDirective(SourceLocation HashLoc, Token &EmbedTok,
39913991
StringRef OriginalFilename = Filename;
39923992
bool isAngled =
39933993
GetIncludeFilenameSpelling(FilenameTok.getLocation(), Filename);
3994+
39943995
// If GetIncludeFilenameSpelling set the start ptr to null, there was an
39953996
// error.
3996-
assert(!Filename.empty());
3997+
if (Filename.empty())
3998+
return;
3999+
39974000
OptionalFileEntryRef MaybeFileRef =
39984001
this->LookupEmbedFile(Filename, isAngled, true, LookupFromFile);
39994002
if (!MaybeFileRef) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %clang_cc1 -std=c23 %s -E -verify
2+
3+
#embed <> // expected-error {{empty filename}}
4+
#embed "" // expected-error {{empty filename}}

0 commit comments

Comments
 (0)