]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR preprocessor/57580 (Repeated _Pragma message directives in macro...
authorJakub Jelinek <jakub@redhat.com>
Thu, 11 Feb 2016 09:09:00 +0000 (10:09 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 11 Feb 2016 09:09:00 +0000 (10:09 +0100)
Backported from mainline
2015-12-03  Jakub Jelinek  <jakub@redhat.com>

PR preprocessor/57580
* c-ppoutput.c (print): Change printed field to bool.
(init_pp_output): Set print.printed to false instead of 0.
(scan_translation_unit): Fix up formatting.  Set print.printed
to true after printing something other than newline.
(scan_translation_unit_trad): Set print.printed to true instead of 1.
(maybe_print_line_1): Set print.printed to false instead of 0.
(print_line_1): Likewise.
(do_line_change): Set print.printed to true instead of 1.
(cb_define, dump_queued_macros, cb_include, cb_def_pragma,
dump_macro): Set print.printed to false after printing newline.

* c-c++-common/cpp/pr57580.c: New test.
* c-c++-common/gomp/pr57580.c: New test.

From-SVN: r233321

gcc/c-family/ChangeLog
gcc/c-family/c-ppoutput.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/cpp/pr57580.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/pr57580.c [new file with mode: 0644]

index 86ecae988f3668db07e29989cf2dcf4ecb2a0635..a51b2a2e93f95e33647a6affe5424df04cc67898 100644 (file)
@@ -1,3 +1,20 @@
+2016-02-11  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2015-12-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR preprocessor/57580
+       * c-ppoutput.c (print): Change printed field to bool.
+       (init_pp_output): Set print.printed to false instead of 0.
+       (scan_translation_unit): Fix up formatting.  Set print.printed
+       to true after printing something other than newline.
+       (scan_translation_unit_trad): Set print.printed to true instead of 1.
+       (maybe_print_line_1): Set print.printed to false instead of 0.
+       (print_line_1): Likewise.
+       (do_line_change): Set print.printed to true instead of 1.
+       (cb_define, dump_queued_macros, cb_include, cb_def_pragma,
+       dump_macro): Set print.printed to false after printing newline.
+
 2015-06-26  Release Manager
 
        * GCC 4.9.3 released.
index f3b5fa4487db4089e58aea08b9163bd3c601ac28..62598e98808628826393cfe0571bcdff3a382b2a 100644 (file)
@@ -33,7 +33,7 @@ static struct
   const cpp_token *prev;       /* Previous token.  */
   const cpp_token *source;     /* Source token for spacing.  */
   int src_line;                        /* Line number currently being written.  */
-  unsigned char printed;       /* Nonzero if something output at line.  */
+  bool printed;                        /* True if something output at line.  */
   bool first_time;             /* pp_file_change hasn't been called yet.  */
   const char *src_file;                /* Current source file.  */
 } print;
@@ -151,7 +151,7 @@ init_pp_output (FILE *out_stream)
 
   /* Initialize the print structure.  */
   print.src_line = 1;
-  print.printed = 0;
+  print.printed = false;
   print.prev = 0;
   print.outf = out_stream;
   print.first_time = 1;
@@ -202,12 +202,16 @@ scan_translation_unit (cpp_reader *pfile)
            {
              do_line_change (pfile, token, loc, false);
              putc (' ', print.outf);
+             print.printed = true;
            }
          else if (print.source->flags & PREV_WHITE
                   || (print.prev
                       && cpp_avoid_paste (pfile, print.prev, token))
                   || (print.prev == NULL && token->type == CPP_HASH))
-           putc (' ', print.outf);
+           {
+             putc (' ', print.outf);
+             print.printed = true;
+           }
        }
       else if (token->flags & PREV_WHITE)
        {
@@ -218,6 +222,7 @@ scan_translation_unit (cpp_reader *pfile)
              && !in_pragma)
            do_line_change (pfile, token, loc, false);
          putc (' ', print.outf);
+         print.printed = true;
        }
 
       avoid_paste = false;
@@ -235,7 +240,7 @@ scan_translation_unit (cpp_reader *pfile)
            fprintf (print.outf, "%s %s", space, name);
          else
            fprintf (print.outf, "%s", name);
-         print.printed = 1;
+         print.printed = true;
          in_pragma = true;
        }
       else if (token->type == CPP_PRAGMA_EOL)
@@ -246,9 +251,9 @@ scan_translation_unit (cpp_reader *pfile)
       else
        {
          if (cpp_get_options (parse_in)->debug)
-             linemap_dump_location (line_table, token->src_loc,
-                                    print.outf);
+           linemap_dump_location (line_table, token->src_loc, print.outf);
          cpp_output_token (token, print.outf);
+         print.printed = true;
        }
 
       /* CPP_COMMENT tokens and raw-string literal tokens can
@@ -298,7 +303,7 @@ scan_translation_unit_trad (cpp_reader *pfile)
       size_t len = pfile->out.cur - pfile->out.base;
       maybe_print_line (pfile->out.first_line);
       fwrite (pfile->out.base, 1, len, print.outf);
-      print.printed = 1;
+      print.printed = true;
       if (!CPP_OPTION (pfile, discard_comments))
        account_for_newlines (pfile->out.base, len);
     }
@@ -319,7 +324,7 @@ maybe_print_line_1 (source_location src_loc, FILE *stream)
     {
       putc ('\n', stream);
       print.src_line++;
-      print.printed = 0;
+      print.printed = false;
     }
 
   if (!flag_no_line_commands
@@ -360,7 +365,7 @@ print_line_1 (source_location src_loc, const char *special_flags, FILE *stream)
   /* End any previous line of text.  */
   if (print.printed)
     putc ('\n', stream);
-  print.printed = 0;
+  print.printed = false;
 
   if (!flag_no_line_commands)
     {
@@ -429,7 +434,7 @@ do_line_change (cpp_reader *pfile, const cpp_token *token,
   if (!CPP_OPTION (pfile, traditional))
     {
       int spaces = LOCATION_COLUMN (src_loc) - 2;
-      print.printed = 1;
+      print.printed = true;
 
       while (-- spaces >= 0)
        putc (' ', print.outf);
@@ -470,6 +475,7 @@ cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node)
     fputs ((const char *) NODE_NAME (node), print.outf);
 
   putc ('\n', print.outf);
+  print.printed = false;
   linemap_resolve_location (line_table, line,
                            LRK_MACRO_DEFINITION_LOCATION,
                            &map);
@@ -521,7 +527,7 @@ dump_queued_macros (cpp_reader *pfile ATTRIBUTE_UNUSED)
     {
       putc ('\n', print.outf);
       print.src_line++;
-      print.printed = 0;
+      print.printed = false;
     }
 
   for (q = define_queue; q;)
@@ -530,6 +536,7 @@ dump_queued_macros (cpp_reader *pfile ATTRIBUTE_UNUSED)
       fputs ("#define ", print.outf);
       fputs (q->macro, print.outf);
       putc ('\n', print.outf);
+      print.printed = false;
       print.src_line++;
       oq = q;
       q = q->next;
@@ -573,6 +580,7 @@ cb_include (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
     }
 
   putc ('\n', print.outf);
+  print.printed = false;
   print.src_line++;
 }
 
@@ -638,6 +646,7 @@ cb_def_pragma (cpp_reader *pfile, source_location line)
   maybe_print_line (line);
   fputs ("#pragma ", print.outf);
   cpp_output_line (pfile, print.outf);
+  print.printed = false;
   print.src_line++;
 }
 
@@ -651,6 +660,7 @@ dump_macro (cpp_reader *pfile, cpp_hashnode *node, void *v ATTRIBUTE_UNUSED)
       fputs ((const char *) cpp_macro_definition (pfile, node),
             print.outf);
       putc ('\n', print.outf);
+      print.printed = false;
       print.src_line++;
     }
 
index c5dd7b58f8c01849885e3410961182572ff34955..3db0586c4bfe5a1b74781e85b5612f2f96e287cc 100644 (file)
@@ -1,6 +1,12 @@
 2016-02-11  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2015-12-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR preprocessor/57580
+       * c-c++-common/cpp/pr57580.c: New test.
+       * c-c++-common/gomp/pr57580.c: New test.
+
        2015-11-21  Jakub Jelinek  <jakub@redhat.com>
 
        PR debug/66432
diff --git a/gcc/testsuite/c-c++-common/cpp/pr57580.c b/gcc/testsuite/c-c++-common/cpp/pr57580.c
new file mode 100644 (file)
index 0000000..1039e21
--- /dev/null
@@ -0,0 +1,9 @@
+/* PR preprocessor/57580 */
+/* { dg-do compile } */
+/* { dg-options "-save-temps" } */
+
+#define MSG    \
+  _Pragma("message(\"message0\")")     \
+  _Pragma("message(\"message1\")")
+MSG    /* { dg-message "message0" } */
+/* { dg-message "message1" "" { target *-*-* } 8 } */
diff --git a/gcc/testsuite/c-c++-common/gomp/pr57580.c b/gcc/testsuite/c-c++-common/gomp/pr57580.c
new file mode 100644 (file)
index 0000000..9bbe707
--- /dev/null
@@ -0,0 +1,36 @@
+/* PR preprocessor/57580 */
+/* { dg-do compile } */
+/* { dg-options "-fopenmp -save-temps -fdump-tree-gimple" } */
+
+#define PS \
+  _Pragma("omp parallel num_threads(2)") \
+  { \
+    _Pragma("omp single") \
+    { \
+      ret = 0; \
+    } \
+  }
+
+int
+main ()
+{
+  int ret;
+  _Pragma("omp parallel num_threads(3)")
+  {
+    _Pragma("omp single")
+    {
+      ret = 0;
+    }
+  }
+  _Pragma("omp parallel num_threads(4)") { _Pragma("omp single") { ret = 0; } }
+  { _Pragma("omp parallel num_threads(5)") { _Pragma("omp single") { ret = 0; } } }
+  PS
+  PS
+  return ret;
+}
+
+/* { dg-final { scan-tree-dump-times "#pragma omp parallel\[^\n\r]*num_threads\\(2\\)" 2 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "#pragma omp parallel\[^\n\r]*num_threads\\(3\\)" 1 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "#pragma omp parallel\[^\n\r]*num_threads\\(4\\)" 1 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "#pragma omp parallel\[^\n\r]*num_threads\\(5\\)" 1 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "#pragma omp single" 5 "gimple" } } */