libcpp: Fix up handling of block comments in -fdirectives-only mode [PR103130]

Message ID 20211117092232.GJ2710@tucnak
State Committed
Headers
Series libcpp: Fix up handling of block comments in -fdirectives-only mode [PR103130] |

Commit Message

Jakub Jelinek Nov. 17, 2021, 9:22 a.m. UTC
  Hi!

Normal preprocessing, -fdirectives-only preprocessing before the Nathan's
rewrite, and all other compilers I've tried on godbolt treat even \*/
as end of a block comment, but the new -fdirectives-only handling doesn't.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2021-11-17  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/103130
	* lex.c (cpp_directive_only_process): Treat even \*/ as end of block
	comment.

	* c-c++-common/cpp/dir-only-9.c: New test.


	Jakub
  

Comments

Marek Polacek Nov. 17, 2021, 3:59 p.m. UTC | #1
On Wed, Nov 17, 2021 at 10:22:32AM +0100, Jakub Jelinek wrote:
> Hi!
> 
> Normal preprocessing, -fdirectives-only preprocessing before the Nathan's
> rewrite, and all other compilers I've tried on godbolt treat even \*/
> as end of a block comment, but the new -fdirectives-only handling doesn't.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

OK for trunk and 11, thanks.
 
> 2021-11-17  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR preprocessor/103130
> 	* lex.c (cpp_directive_only_process): Treat even \*/ as end of block
> 	comment.
> 
> 	* c-c++-common/cpp/dir-only-9.c: New test.
> 
> --- libcpp/lex.c.jj	2021-11-01 14:37:06.706853026 +0100
> +++ libcpp/lex.c	2021-11-16 16:54:04.022644499 +0100
> @@ -4493,7 +4493,7 @@ cpp_directive_only_process (cpp_reader *
>  			break;
>  
>  		      case '*':
> -			if (pos > peek && !esc)
> +			if (pos > peek)
>  			  star = is_block;
>  			esc = false;
>  			break;
> --- gcc/testsuite/c-c++-common/cpp/dir-only-9.c.jj	2021-11-16 16:56:57.121217975 +0100
> +++ gcc/testsuite/c-c++-common/cpp/dir-only-9.c	2021-11-16 16:56:14.524815094 +0100
> @@ -0,0 +1,13 @@
> +/* PR preprocessor/103130 */
> +/* { dg-do preprocess } */
> +/* { dg-options -fdirectives-only } */
> +
> +/*\
> + * this is a comment
> +\*/
> +
> +int
> +main ()
> +{
> +  return 0;
> +}
> 
> 	Jakub
> 

Marek
  

Patch

--- libcpp/lex.c.jj	2021-11-01 14:37:06.706853026 +0100
+++ libcpp/lex.c	2021-11-16 16:54:04.022644499 +0100
@@ -4493,7 +4493,7 @@  cpp_directive_only_process (cpp_reader *
 			break;
 
 		      case '*':
-			if (pos > peek && !esc)
+			if (pos > peek)
 			  star = is_block;
 			esc = false;
 			break;
--- gcc/testsuite/c-c++-common/cpp/dir-only-9.c.jj	2021-11-16 16:56:57.121217975 +0100
+++ gcc/testsuite/c-c++-common/cpp/dir-only-9.c	2021-11-16 16:56:14.524815094 +0100
@@ -0,0 +1,13 @@ 
+/* PR preprocessor/103130 */
+/* { dg-do preprocess } */
+/* { dg-options -fdirectives-only } */
+
+/*\
+ * this is a comment
+\*/
+
+int
+main ()
+{
+  return 0;
+}