c-ppoutput.c (scan_translation_unit): Call account_for_newlines for all CPP_TOKEN_FLD...
authorJakub Jelinek <jakub@redhat.com>
Wed, 10 Jul 2013 16:49:24 +0000 (18:49 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 10 Jul 2013 16:49:24 +0000 (18:49 +0200)
* c-ppoutput.c (scan_translation_unit): Call account_for_newlines
for all CPP_TOKEN_FLD_STR tokens, not just CPP_COMMENT.

* include/cpplib.h (cpp_token_val_index): Change parameter type to
const cpp_token *.
* lex.c (cpp_token_val_index): Likewise.

* c-c++-common/raw-string-18.c: New test.
* c-c++-common/raw-string-19.c: New test.

From-SVN: r200878

gcc/c-family/ChangeLog
gcc/c-family/c-ppoutput.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/raw-string-18.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/raw-string-19.c [new file with mode: 0644]
libcpp/ChangeLog
libcpp/include/cpplib.h
libcpp/lex.c

index 0506e55dd47b8cec87b850fde40fabf62c12be45..1211fcc6727bcadc9313c99566daa23d90571afa 100644 (file)
@@ -1,3 +1,8 @@
+2013-07-10  Jakub Jelinek  <jakub@redhat.com>
+
+       * c-ppoutput.c (scan_translation_unit): Call account_for_newlines
+       for all CPP_TOKEN_FLD_STR tokens, not just CPP_COMMENT.
+
 2013-07-10  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/57869
index 4a1534667f6a2c5c576120cbc8dae0cba615ad0b..03b881705209bec90035155e8a9e38b2730759e9 100644 (file)
@@ -251,7 +251,11 @@ scan_translation_unit (cpp_reader *pfile)
          cpp_output_token (token, print.outf);
        }
 
-      if (token->type == CPP_COMMENT)
+      /* CPP_COMMENT tokens and raw-string literal tokens can
+        have embedded new-line characters.  Rather than enumerating
+        all the possible token types just check if token uses
+        val.str union member.  */
+      if (cpp_token_val_index (token) == CPP_TOKEN_FLD_STR)
        account_for_newlines (token->val.str.text, token->val.str.len);
     }
 }
index 520818f0199945481fa7125b394cfe1fbc502730..c32ac8452b2d6fd9277a55beb2adf81e2fe552a6 100644 (file)
@@ -8,6 +8,9 @@
 
 2013-07-10  Jakub Jelinek  <jakub@redhat.com>
 
+       * c-c++-common/raw-string-18.c: New test.
+       * c-c++-common/raw-string-19.c: New test.
+
        PR preprocessor/57757
        * g++.dg/cpp/paste1.C: New test.
        * g++.dg/cpp/paste2.C: New test.
diff --git a/gcc/testsuite/c-c++-common/raw-string-18.c b/gcc/testsuite/c-c++-common/raw-string-18.c
new file mode 100644 (file)
index 0000000..8d4381d
--- /dev/null
@@ -0,0 +1,21 @@
+/* PR preprocessor/57824 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -fdump-tree-optimized-lineno" { target c } } */
+/* { dg-options "-std=c++11 -fdump-tree-optimized-lineno" { target c++ } } */
+
+const char x[] = R"(
+abc
+def
+ghi
+)";
+
+int
+main ()
+{
+  extern void foo (); foo ();
+  return 0;
+}
+
+/* Verify call to foo is on line 15.  */
+/* { dg-final { scan-tree-dump ": 15\[]:]\[^\n\r]*foo" "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/testsuite/c-c++-common/raw-string-19.c b/gcc/testsuite/c-c++-common/raw-string-19.c
new file mode 100644 (file)
index 0000000..08121a8
--- /dev/null
@@ -0,0 +1,22 @@
+/* PR preprocessor/57824 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -fdump-tree-optimized-lineno -save-temps" { target c } } */
+/* { dg-options "-std=c++11 -fdump-tree-optimized-lineno -save-temps" { target c++ } } */
+
+const char x[] = R"(
+abc
+def
+ghi
+)";
+
+int
+main ()
+{
+  extern void foo (); foo ();
+  return 0;
+}
+
+/* Verify call to foo is on line 15.  */
+/* { dg-final { scan-tree-dump ": 15\[]:]\[^\n\r]*foo" "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
+/* { dg-final { cleanup-saved-temps } } */
index d0c583d86913b48d0467e12a94143f008a344b12..195d728440ccedcb25040de09e2e9d070442eaae 100644 (file)
@@ -1,5 +1,9 @@
 2013-07-10  Jakub Jelinek  <jakub@redhat.com>
 
+       * include/cpplib.h (cpp_token_val_index): Change parameter type to
+       const cpp_token *.
+       * lex.c (cpp_token_val_index): Likewise.
+
        PR preprocessor/57757
        * lex.c (cpp_avoid_paste): Avoid pasting CPP_{,W,UTF8}STRING
        or CPP_STRING{16,32} with CPP_NAME or SPELL_LITERAL token that
index 76c297acdcbd4b77149dedd769af54d69b570004..6c4225c8be7d4b42fa969d64ebebbbd3cb4487a0 100644 (file)
@@ -248,7 +248,7 @@ struct GTY(()) cpp_token {
 };
 
 /* Say which field is in use.  */
-extern enum cpp_token_fld_kind cpp_token_val_index (cpp_token *tok);
+extern enum cpp_token_fld_kind cpp_token_val_index (const cpp_token *tok);
 
 /* A type wide enough to hold any multibyte source character.
    cpplib's character constant interpreter requires an unsigned type.
index dc7b9c17ddc3961a5ee8a500ab78d6e24029e69a..84e2af695d12a9ee537e3bea6a19f3b07c82e696 100644 (file)
@@ -3029,7 +3029,7 @@ _cpp_aligned_alloc (cpp_reader *pfile, size_t len)
 /* Say which field of TOK is in use.  */
 
 enum cpp_token_fld_kind
-cpp_token_val_index (cpp_token *tok)
+cpp_token_val_index (const cpp_token *tok)
 {
   switch (TOKEN_SPELL (tok))
     {