re PR preprocessor/58893 (<command-line>:0:0: internal compiler error: Segmentation...
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Tue, 30 Sep 2014 16:08:53 +0000 (16:08 +0000)
committerBernd Edlinger <edlinger@gcc.gnu.org>
Tue, 30 Sep 2014 16:08:53 +0000 (16:08 +0000)
2014-09-30  Bernd Edlinger  <bernd.edlinger@hotmail.de>

PR preprocessor/58893
* errors.c (cpp_diagnostic): Fix possible out of bounds access.
* files.c (_cpp_stack_include): Initialize src_loc for IT_CMDLINE.

testsuite:
2014-09-30  Bernd Edlinger  <bernd.edlinger@hotmail.de>

PR preprocessor/58893
* gcc.dg/pr58893.c: New test case.
* gcc.dg/pr58893-0.h: New include.

From-SVN: r215730

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr58893-0.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr58893.c [new file with mode: 0644]
libcpp/ChangeLog
libcpp/errors.c
libcpp/files.c

index 858df23c8ee1f5a6f1ba17334bff8648c412fbf6..6ffbbee2720f871b6b1d75de4283c2b5088b4c78 100644 (file)
@@ -1,3 +1,9 @@
+2014-09-30  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+       PR preprocessor/58893
+       * gcc.dg/pr58893.c: New test case.
+       * gcc.dg/pr58893-0.h: New include.
+
 2014-09-30  Ilya Tocar  <ilya.tocar@intel.com>
 
        PR middle-end/62120
diff --git a/gcc/testsuite/gcc.dg/pr58893-0.h b/gcc/testsuite/gcc.dg/pr58893-0.h
new file mode 100644 (file)
index 0000000..957bcdc
--- /dev/null
@@ -0,0 +1 @@
+#pragma GCC visibility push(hidden)
diff --git a/gcc/testsuite/gcc.dg/pr58893.c b/gcc/testsuite/gcc.dg/pr58893.c
new file mode 100644 (file)
index 0000000..c9f8b6b
--- /dev/null
@@ -0,0 +1,5 @@
+/* PR preprocessor/58893 */
+/* { dg-do compile } */
+/* { dg-options "-include pr58893-0.h -include pr58893-1.h -I${srcdir}/gcc.dg" } */
+/* { dg-error "pr58893-1.h: No such file or directory" "" { target *-*-* } 0 } */
+/* { dg-prune-output "compilation terminated" } */
index 463bb60e7614d57ef9c57bcde012e35422cd9862..92999040a02a629c69bbc18565d619ecffbbd6b8 100644 (file)
@@ -1,3 +1,9 @@
+2014-09-30  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+       PR preprocessor/58893
+       * errors.c (cpp_diagnostic): Fix possible out of bounds access.
+       * files.c (_cpp_stack_include): Initialize src_loc for IT_CMDLINE.
+
 2014-09-24  Marek Polacek  <polacek@redhat.com>
 
        PR c/61405
index d1ca7a12ff42c72f873a9a4af7061f796524578b..bc857f0b81d5d3d4acf624be0adff409fd267462 100644 (file)
@@ -48,10 +48,7 @@ cpp_diagnostic (cpp_reader * pfile, int level, int reason,
      current run -- that is invalid.  */
   else if (pfile->cur_token == pfile->cur_run->base)
     {
-      if (pfile->cur_run->prev != NULL)
-       src_loc = pfile->cur_run->prev->limit->src_loc;
-      else
-       src_loc = 0;
+      src_loc = 0;
     }
   else
     {
index a442783f1d1902edf1be16ea39fb2c74853b2b53..00302fd774f328960463eeb97b0d008d29a381a2 100644 (file)
@@ -991,6 +991,18 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets,
   _cpp_file *file;
   bool stacked;
 
+  /* For -include command-line flags we have type == IT_CMDLINE.
+     When the first -include file is processed we have the case, where
+     pfile->cur_token == pfile->cur_run->base, we are directly called up
+     by the front end.  However in the case of the second -include file,
+     we are called from _cpp_lex_token -> _cpp_get_fresh_line ->
+     cpp_push_include, with pfile->cur_token != pfile->cur_run->base,
+     and pfile->cur_token[-1].src_loc not (yet) initialized.
+     However, when the include file cannot be found, we need src_loc to
+     be initialized to some safe value: 0 means UNKNOWN_LOCATION.  */
+  if (type == IT_CMDLINE && pfile->cur_token != pfile->cur_run->base)
+    pfile->cur_token[-1].src_loc = 0;
+
   dir = search_path_head (pfile, fname, angle_brackets, type);
   if (!dir)
     return false;