Skip to content

Commit 3bd97c2

Browse files
Fznamznonsivan-shani
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 c8b1acb commit 3bd97c2

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ Improvements to Coverage Mapping
147147
Bug Fixes in This Version
148148
-------------------------
149149

150+
- Clang now outputs correct values when #embed data contains bytes with negative
151+
signed char values (#GH102798).
152+
150153
Bug Fixes to Compiler Builtins
151154
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
152155

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)