diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 03c420bcfd932..e716efa46a1f0 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -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 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp index 1005825441b3e..2ae355fb33885 100644 --- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -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(*Iter); + *Callbacks->OS << static_cast(Byte); PrintComma = true; } } else if (Tok.isAnnotation()) { diff --git a/clang/test/Preprocessor/embed_preprocess_to_file.c b/clang/test/Preprocessor/embed_preprocess_to_file.c index 9895d958cf96d..b3c99d36f784a 100644 --- a/clang/test/Preprocessor/embed_preprocess_to_file.c +++ b/clang/test/Preprocessor/embed_preprocess_to_file.c @@ -37,3 +37,11 @@ const char even_more[] = { // DIRECTIVE-NEXT: #embed prefix(4, 5,) suffix(, 6, 7) /* clang -E -dE */ // DIRECTIVE-NEXT: , 8, 9, 10 // DIRECTIVE-NEXT: }; + +constexpr char big_one[] = { +#embed +}; + +// EXPANDED: constexpr char big_one[] = {255 +// DIRECTIVE: constexpr char big_one[] = { +// DIRECTIVE-NEXT: #embed