This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.

--- 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 ();
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]