Skip to content
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

[clang] Fix preprocessor output from #embed (#126742) #127222

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,8 @@ Bug Fixes in This Version
- No longer return ``false`` for ``noexcept`` expressions involving a
``delete`` which resolves to a destroying delete but the type of the object
being deleted has a potentially throwing destructor (#GH118660).
- Clang now outputs correct values when #embed data contains bytes with negative
signed char values (#GH102798).

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/Frontend/PrintPreprocessedOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,11 +974,10 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
// Loop over the contents and print them as a comma-delimited list of
// values.
bool PrintComma = false;
for (auto Iter = Data->BinaryData.begin(), End = Data->BinaryData.end();
Iter != End; ++Iter) {
for (unsigned char Byte : Data->BinaryData.bytes()) {
if (PrintComma)
*Callbacks->OS << ", ";
*Callbacks->OS << static_cast<unsigned>(*Iter);
*Callbacks->OS << static_cast<int>(Byte);
PrintComma = true;
}
} else if (Tok.isAnnotation()) {
Expand Down
8 changes: 8 additions & 0 deletions clang/test/Preprocessor/embed_preprocess_to_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ const char even_more[] = {
// DIRECTIVE-NEXT: #embed <jk.txt> prefix(4, 5,) suffix(, 6, 7) /* clang -E -dE */
// DIRECTIVE-NEXT: , 8, 9, 10
// DIRECTIVE-NEXT: };

constexpr char big_one[] = {
#embed <big_char.txt>
};

// EXPANDED: constexpr char big_one[] = {255
// DIRECTIVE: constexpr char big_one[] = {
// DIRECTIVE-NEXT: #embed <big_char.txt>
Loading