-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[Clang] prevent assertion on empty filename in #embed directive #163072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: Oleksandr T. (a-tarasyuk) ChangesFixes #162951 This PR addresses the issue of Clang asserting when processing #embed <> Full diff: https://github.com/llvm/llvm-project/pull/163072.diff 3 Files Affected:
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..dd73e72b0a488
--- /dev/null
+++ b/clang/test/Preprocessor/embed_empty_file.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -std=c23 %s -E -verify
+
+#embed <> // expected-error {{empty filename}}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
…#163072) Fixes llvm#162951 --- This PR addresses the issue of Clang asserting when processing `#embed` with an empty filename ```c #embed <> ```
Fixes #162951
This PR addresses the issue of Clang asserting when processing
#embed
with an empty filename#embed <>