When processing CRLF sequences, _cpp_clean_line correctly incremented the source pointer 's' to skip over the CR character, but forgot to update the destination pointer 'd' to the same location. This caused both the CR and LF characters to be written to the output buffer, outputting LFLF instead of the intended LF.
libcpp/ChangeLog: PR preprocessor/88424 * lex.cc (_cpp_clean_line): Update destination pointer when skipping CR in CRLF sequence to prevent double line feeds. gcc/testsuite/ChangeLog: PR preprocessor/88424 * gcc.dg/cpp/pr88424.c: New test to verify CRLF handling in comments with -C option. Signed-off-by: Peter Damianov <peter0...@disroot.org> --- gcc/testsuite/gcc.dg/cpp/pr88424.c | 17 +++++++++++++++++ libcpp/lex.cc | 1 + 2 files changed, 18 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/cpp/pr88424.c diff --git a/gcc/testsuite/gcc.dg/cpp/pr88424.c b/gcc/testsuite/gcc.dg/cpp/pr88424.c new file mode 100644 index 00000000000..591856b6197 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/pr88424.c @@ -0,0 +1,17 @@ +/* { dg-do preprocess } */ +/* { dg-options "-C" } */ + +/* Test that CRLF line endings in comments are preserved correctly with -C. + Previously, the preprocessor would convert CRLF sequences in comments + to LFLF, causing extra blank lines in the output. + + This test ensures that comments with CRLF line endings maintain their + original number of newlines when processed with the -C option. */ + +/* This comment has CRLF line endings + and should appear as two lines in the output, not three. */ + +/* Check that we don't get double line feeds. */ +/* { dg-final { scan-file-not pr88424.i "comment has CRLF line endings\n\n and should appear" } } */ +/* Check that the comment does appear correctly with single line feed. */ +/* { dg-final { scan-file pr88424.i "comment has CRLF line endings\n and should appear" } } */ \ No newline at end of file diff --git a/libcpp/lex.cc b/libcpp/lex.cc index 2ba9d588708..d8938fbadc5 100644 --- a/libcpp/lex.cc +++ b/libcpp/lex.cc @@ -944,6 +944,7 @@ _cpp_clean_line (cpp_reader *pfile) if (__builtin_expect (c == '\r', false) && s[1] == '\n') { s++; + d = (uchar *) s; /* Move d to point to the LF, not the CR */ if (s == buffer->rlimit) goto done; } -- 2.39.5