[clang] Fix preprocessor output from #embed (#126742) · llvm/llvm-project@8e06e0e (original) (raw)

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -897,6 +897,8 @@ Bug Fixes in This Version
897 897 - No longer return ``false`` for ``noexcept`` expressions involving a
898 898 ``delete`` which resolves to a destroying delete but the type of the object
899 899 being deleted has a potentially throwing destructor (#GH118660).
900 +- Clang now outputs correct values when #embed data contains bytes with negative
901 + signed char values (#GH102798).
900 902
901 903 Bug Fixes to Compiler Builtins
902 904 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -974,11 +974,10 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
974 974 // Loop over the contents and print them as a comma-delimited list of
975 975 // values.
976 976 bool PrintComma = false;
977 -for (auto Iter = Data->BinaryData.begin(), End = Data->BinaryData.end();
978 - Iter != End; ++Iter) {
977 +for (unsigned char Byte : Data->BinaryData.bytes()) {
979 978 if (PrintComma)
980 979 *Callbacks->OS << ", ";
981 - *Callbacks->OS << static_cast<unsigned>(*Iter);
980 + *Callbacks->OS << static_cast<int>(Byte);
982 981 PrintComma = true;
983 982 }
984 983 } else if (Tok.isAnnotation()) {
Original file line number Diff line number Diff line change
@@ -37,3 +37,11 @@ const char even_more[] = {
37 37 // DIRECTIVE-NEXT: #embed <jk.txt> prefix(4, 5,) suffix(, 6, 7) /* clang -E -dE */
38 38 // DIRECTIVE-NEXT: , 8, 9, 10
39 39 // DIRECTIVE-NEXT: };
40 +
41 +constexpr char big_one[] = {
42 +#embed <big_char.txt>
43 +};
44 +
45 +// EXPANDED: constexpr char big_one[] = {255
46 +// DIRECTIVE: constexpr char big_one[] = {
47 +// DIRECTIVE-NEXT: #embed <big_char.txt>