Patchwork Allow raw-string literals in macro arguments and deferred pragmas (PR preprocessor/57824)

login
register
mail settings
Submitter Jakub Jelinek
Date July 5, 2013, 3:19 p.m.
Message ID <20130705151950.GY2336@tucnak.redhat.com>
Download mbox | patch
Permalink /patch/257190/
State New
Headers show

Comments

Jakub Jelinek - July 5, 2013, 3:19 p.m.
Hi!

When adding lex_raw_stirng, I've struggled with the fetching of
new lines, cpp_get_fresh_line can't be called under all circumstances,
and thus for some conditions I just gave up with error.
Seems for deferred_pragmas it just works and for parsing of arguments
also if there is something in the current buffer (otherwise would
that just mean and of say include? I think raw strings shouldn't be allowed
to flow from end of include file to another file).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2013-07-05  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/57824
	* lex.c (lex_raw_string): Allow reading new-lines if
	in_deferred_pragma or if parsing_args and there is still
	data in the current buffer.

	* c-c++-common/raw-string-17.c: New test.
	* c-c++-common/gomp/pr57824.c: New test.


	Jakub
Jason Merrill - July 10, 2013, 6:32 a.m.
On 07/05/2013 11:19 AM, Jakub Jelinek wrote:
> Seems for deferred_pragmas it just works

Can we encounter a newline in a deferred pragma?

> and for parsing of arguments
> also if there is something in the current buffer (otherwise would
> that just mean and of say include? I think raw strings shouldn't be allowed
> to flow from end of include file to another file).

Agreed: "A source file shall not end in a partial preprocessing token".

OK.

Jason
Jakub Jelinek - July 10, 2013, 3:41 p.m.
On Wed, Jul 10, 2013 at 02:32:07AM -0400, Jason Merrill wrote:
> On 07/05/2013 11:19 AM, Jakub Jelinek wrote:
> >Seems for deferred_pragmas it just works
> 
> Can we encounter a newline in a deferred pragma?

Yes, that is the OpenMP testcase in the patch.

> >and for parsing of arguments
> >also if there is something in the current buffer (otherwise would
> >that just mean and of say include? I think raw strings shouldn't be allowed
> >to flow from end of include file to another file).
> 
> Agreed: "A source file shall not end in a partial preprocessing token".
> 
> OK.

Thanks.

	Jakub

Patch

--- libcpp/lex.c.jj	2013-07-04 18:48:13.000000000 +0200
+++ libcpp/lex.c	2013-07-04 19:16:26.401312503 +0200
@@ -1692,8 +1692,8 @@  lex_raw_string (cpp_reader *pfile, cpp_t
       else if (c == '\n')
 	{
 	  if (pfile->state.in_directive
-	      || pfile->state.parsing_args
-	      || pfile->state.in_deferred_pragma)
+	      || (pfile->state.parsing_args
+		  && pfile->buffer->next_line >= pfile->buffer->rlimit))
 	    {
 	      cur--;
 	      type = CPP_OTHER;
--- gcc/testsuite/c-c++-common/raw-string-17.c.jj	2013-07-04 19:22:07.905695049 +0200
+++ gcc/testsuite/c-c++-common/raw-string-17.c	2013-07-04 19:26:30.136244380 +0200
@@ -0,0 +1,30 @@ 
+/* PR preprocessor/57824 */
+/* { dg-do run } */
+/* { dg-options "-std=gnu99" { target c } } */
+/* { dg-options "-std=c++11" { target c++ } } */
+
+#define S(s) s
+#define T(s) s "\n"
+
+const char x[] = R"(
+abc
+)";
+const char y[] = S(R"(
+abc
+)");
+const char z[] = "\nabc\n";
+const char w[] = T(R"(
+abc)");
+
+int
+main ()
+{
+  if (sizeof x != sizeof y
+      || sizeof x != sizeof z
+      || sizeof x != sizeof w
+      || __builtin_memcmp (x, y, sizeof x)
+      || __builtin_memcmp (x, z, sizeof x)
+      || __builtin_memcmp (x, w, sizeof x))
+    __builtin_abort ();
+  return 0;
+}
--- gcc/testsuite/c-c++-common/gomp/pr57824.c.jj	2013-07-04 19:30:26.040563509 +0200
+++ gcc/testsuite/c-c++-common/gomp/pr57824.c	2013-07-04 19:30:56.928056024 +0200
@@ -0,0 +1,14 @@ 
+/* PR preprocessor/57824 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -fopenmp" { target c } } */
+/* { dg-options "-std=c++11 -fopenmp" { target c++ } } */
+
+void bar ();
+
+void foo ()
+{
+#pragma omp parallel num_threads(sizeof R"(
+abc
+)")
+  bar ();
+}