Skip to content

Commit e050817

Browse files
committed
[Clang] prevent assertion on empty filename in #embed directive
1 parent 4bf5ab4 commit e050817

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

clang/docs/ReleaseNotes.rst

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

409410
Bug Fixes to Compiler Builtins
410411
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// RUN: %clang_cc1 -std=c23 %s -E -verify
2+
3+
#embed <> // expected-error {{empty filename}}

0 commit comments

Comments
 (0)