[clang] [clang] Fix incorrect line numbers with -E and raw string (#47577) (PR #77021)
https://github.com/stevecor created https://github.com/llvm/llvm-project/pull/77021 When printing preprocessed tokens, handle newlines in string literals because raw string literals may contain newlines. >From 47aa72d5e68c08657a519c3d0a3a73fbd1c89372 Mon Sep 17 00:00:00 2001 From: Steve Cornett <21205494+steve...@users.noreply.github.com> Date: Thu, 4 Jan 2024 14:52:11 -0800 Subject: [PATCH] Fix incorrect line numbers with -E and raw string (#47577) When printing preprocessed tokens, handle newlines in string literals because raw string literals may contain newlines. --- clang/lib/Frontend/PrintPreprocessedOutput.cpp | 4 clang/test/Frontend/raw_string_line_number.cpp | 6 ++ 2 files changed, 10 insertions(+) create mode 100644 clang/test/Frontend/raw_string_line_number.cpp diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp index 7f5f6690682300..6ac8379e07d90f 100644 --- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -886,6 +886,10 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok, *Callbacks->OS << II->getName(); } else if (Tok.isLiteral() && !Tok.needsCleaning() && Tok.getLiteralData()) { + if (tok::isStringLiteral(Tok.getKind())) { +// Raw string literal may contain newlines +Callbacks->HandleNewlinesInToken(Tok.getLiteralData(), Tok.getLength()); + } Callbacks->OS->write(Tok.getLiteralData(), Tok.getLength()); } else if (Tok.getLength() < std::size(Buffer)) { const char *TokPtr = Buffer; diff --git a/clang/test/Frontend/raw_string_line_number.cpp b/clang/test/Frontend/raw_string_line_number.cpp new file mode 100644 index 00..0aaaec2906bede --- /dev/null +++ b/clang/test/Frontend/raw_string_line_number.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -E %s | FileCheck %s +// CHECK: AAA +// CHECK-NEXT: BBB +R"( +AAA)" +BBB ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix incorrect line numbers with -E and raw string (#47577) (PR #77021)
stevecor wrote: Ping https://github.com/llvm/llvm-project/pull/77021 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix incorrect line numbers with -E and raw string (#47577) (PR #77021)
stevecor wrote: Ping https://github.com/llvm/llvm-project/pull/77021 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix incorrect line numbers with -E and raw string (#47577) (PR #77021)
@@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -E %s | FileCheck %s +// CHECK: AAA +// CHECK-NEXT: BBB +R"( +AAA)" +BBB stevecor wrote: This test demonstrates that the line `AAA` is followed immediately by the line `BBB` with no intervening blank line. Without the fix, there is an incorrect blank line between them. This test fails without the fix. https://github.com/llvm/llvm-project/pull/77021 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix incorrect line numbers with -E and raw string (#47577) (PR #77021)
stevecor wrote: > This will need a release note Are you asking me to do this? I did not see any instructions about how to do this. https://github.com/llvm/llvm-project/pull/77021 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix incorrect line numbers with -E and raw string (#47577) (PR #77021)
stevecor wrote: Ping https://github.com/llvm/llvm-project/pull/77021 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix incorrect line numbers with -E and raw string (#47577) (PR #77021)
stevecor wrote: Ping https://github.com/llvm/llvm-project/pull/77021 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix incorrect line numbers with -E and raw string (#47577) (PR #77021)
https://github.com/stevecor closed https://github.com/llvm/llvm-project/pull/77021 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits