From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 2FA483848010; Mon, 31 May 2021 14:08:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2FA483848010 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-8490] libcpp: Fix up -fdirectives-only handling of // comments on last line not terminated with newline [P X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: f4d6ea0c64bbbbe45add18294bfbd2ceb6512bbd X-Git-Newrev: 3a2fa2e819d4714cecf5048eda2b7e52ba9e3cdd Message-Id: <20210531140844.2FA483848010@sourceware.org> Date: Mon, 31 May 2021 14:08:44 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 May 2021 14:08:44 -0000 https://gcc.gnu.org/g:3a2fa2e819d4714cecf5048eda2b7e52ba9e3cdd commit r11-8490-g3a2fa2e819d4714cecf5048eda2b7e52ba9e3cdd Author: Jakub Jelinek Date: Thu May 20 09:09:07 2021 +0200 libcpp: Fix up -fdirectives-only handling of // comments on last line not terminated with newline [PR100646] As can be seen on the testcases, before the -fdirectives-only preprocessing rewrite the preprocessor would assume // comments are terminated by the end of file even when newline wasn't there, but now we error out. The following patch restores the previous behavior. 2021-05-20 Jakub Jelinek PR preprocessor/100646 * lex.c (cpp_directive_only_process): Treat end of file as termination for !is_block comments. * gcc.dg/cpp/pr100646-1.c: New test. * gcc.dg/cpp/pr100646-2.c: New test. (cherry picked from commit d15a2d261b24adcbfe5e663b15dde3df5d2b3486) Diff: --- gcc/testsuite/gcc.dg/cpp/pr100646-1.c | 5 +++++ gcc/testsuite/gcc.dg/cpp/pr100646-2.c | 6 ++++++ libcpp/lex.c | 5 +++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.dg/cpp/pr100646-1.c b/gcc/testsuite/gcc.dg/cpp/pr100646-1.c new file mode 100644 index 00000000000..8f2caf40c3f --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/pr100646-1.c @@ -0,0 +1,5 @@ +/* PR preprocessor/100646 */ +/* { dg-do compile } */ +/* { dg-options "-fdirectives-only -save-temps -std=c17" } */ +int main () { return 0; } +// Not newline terminated \ No newline at end of file diff --git a/gcc/testsuite/gcc.dg/cpp/pr100646-2.c b/gcc/testsuite/gcc.dg/cpp/pr100646-2.c new file mode 100644 index 00000000000..a1deba10634 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/pr100646-2.c @@ -0,0 +1,6 @@ +/* PR preprocessor/100646 */ +/* { dg-do compile } */ +/* { dg-options "-fdirectives-only -save-temps -std=c17" } */ +int main () { return 0; } +/* { dg-warning "backslash-newline at end of file" "" { target *-*-* } .+1 } */ +// Not newline terminated\ \ No newline at end of file diff --git a/libcpp/lex.c b/libcpp/lex.c index 6c0ca8d2e2d..3791f388207 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -4469,8 +4469,9 @@ cpp_directive_only_process (cpp_reader *pfile, break; } } - cpp_error_with_line (pfile, CPP_DL_ERROR, sloc, 0, - "unterminated comment"); + if (pos < limit || is_block) + cpp_error_with_line (pfile, CPP_DL_ERROR, sloc, 0, + "unterminated comment"); done_comment: lwm = pos; break;