Skip to content

Commit 8e06e0e

Browse files
Fznamznontstellar
authored andcommitted
[clang] Fix preprocessor output from #embed (llvm#126742)
When bytes with negative signed char values appear in the data, make sure to use raw bytes from the data string when preprocessing, not char values. Fixes llvm#102798
1 parent 77195a5 commit 8e06e0e

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,8 @@ Bug Fixes in This Version
897897
- No longer return ``false`` for ``noexcept`` expressions involving a
898898
``delete`` which resolves to a destroying delete but the type of the object
899899
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).
900902

901903
Bug Fixes to Compiler Builtins
902904
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Frontend/PrintPreprocessedOutput.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,11 +974,10 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
974974
// Loop over the contents and print them as a comma-delimited list of
975975
// values.
976976
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()) {
979978
if (PrintComma)
980979
*Callbacks->OS << ", ";
981-
*Callbacks->OS << static_cast<unsigned>(*Iter);
980+
*Callbacks->OS << static_cast<int>(Byte);
982981
PrintComma = true;
983982
}
984983
} else if (Tok.isAnnotation()) {

clang/test/Preprocessor/embed_preprocess_to_file.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,11 @@ const char even_more[] = {
3737
// DIRECTIVE-NEXT: #embed <jk.txt> prefix(4, 5,) suffix(, 6, 7) /* clang -E -dE */
3838
// DIRECTIVE-NEXT: , 8, 9, 10
3939
// 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>

0 commit comments

Comments
 (0)