From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 6BF52385E44B; Thu, 20 May 2021 07:09:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6BF52385E44B 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 r12-934] 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/master X-Git-Oldrev: 75ab8b4829dec8c70470e8225c9add964f71ed74 X-Git-Newrev: d15a2d261b24adcbfe5e663b15dde3df5d2b3486 Message-Id: <20210520070958.6BF52385E44B@sourceware.org> Date: Thu, 20 May 2021 07:09:58 +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: Thu, 20 May 2021 07:09:58 -0000 https://gcc.gnu.org/g:d15a2d261b24adcbfe5e663b15dde3df5d2b3486 commit r12-934-gd15a2d261b24adcbfe5e663b15dde3df5d2b3486 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. 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 6fd722ab263..3618fa5d737 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -4480,8 +4480,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;