]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR preprocessor/60400 (ICE with trigraphs)
authorJakub Jelinek <jakub@redhat.com>
Thu, 6 Mar 2014 07:53:17 +0000 (08:53 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 6 Mar 2014 07:53:17 +0000 (08:53 +0100)
PR preprocessor/60400
Backport from mainline
2013-06-24  Dehao Chen  <dehao@google.com>

* files.c (_cpp_stack_include): Fix the highest_location when header
file is guarded by #ifndef and is included twice.

2014-03-03  Jakub Jelinek  <jakub@redhat.com>

PR preprocessor/60400
* c-c++-common/cpp/pr60400.c: New test.
* c-c++-common/cpp/pr60400-1.h: New file.
* c-c++-common/cpp/pr60400-2.h: New file.

From-SVN: r208362

gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/cpp/pr60400-1.h [new file with mode: 0644]
gcc/testsuite/c-c++-common/cpp/pr60400-2.h [new file with mode: 0644]
gcc/testsuite/c-c++-common/cpp/pr60400.c [new file with mode: 0644]
libcpp/ChangeLog
libcpp/files.c

index d58aae5d2100acf5560d178654808740b4f8987e..a86397f2e1a77b21e82c1851f8b10f2e6717c2a0 100644 (file)
@@ -1,3 +1,13 @@
+2014-03-06  Jakub Jelinek  <jakub@redhat.com>
+
+       Backport from mainline
+       2014-03-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR preprocessor/60400
+       * c-c++-common/cpp/pr60400.c: New test.
+       * c-c++-common/cpp/pr60400-1.h: New file.
+       * c-c++-common/cpp/pr60400-2.h: New file.
+
 2014-03-04  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/60382
diff --git a/gcc/testsuite/c-c++-common/cpp/pr60400-1.h b/gcc/testsuite/c-c++-common/cpp/pr60400-1.h
new file mode 100644 (file)
index 0000000..3e32175
--- /dev/null
@@ -0,0 +1,3 @@
+??=ifndef PR60400_1_H
+??=define PR60400_1_H
+??=endif
diff --git a/gcc/testsuite/c-c++-common/cpp/pr60400-2.h b/gcc/testsuite/c-c++-common/cpp/pr60400-2.h
new file mode 100644 (file)
index 0000000..d9a5906
--- /dev/null
@@ -0,0 +1,4 @@
+??=ifndef PR60400_2_H
+??=define PR60400_2_H
+??=include "pr60400-1.h"
+??=endif
diff --git a/gcc/testsuite/c-c++-common/cpp/pr60400.c b/gcc/testsuite/c-c++-common/cpp/pr60400.c
new file mode 100644 (file)
index 0000000..fc3e0d9
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR preprocessor/60400 */
+/* { dg-do compile } */
+/* { dg-options "-trigraphs -Wtrigraphs" } */
+
+??=include "pr60400-1.h"
+??=include "pr60400-2.h"
+
+/* { dg-warning "trigraph" "" { target *-*-* } 1 } */
+/* { dg-warning "trigraph" "" { target *-*-* } 2 } */
+/* { dg-warning "trigraph" "" { target *-*-* } 3 } */
+/* { dg-warning "trigraph" "" { target *-*-* } 4 } */
+/* { dg-warning "trigraph" "" { target *-*-* } 5 } */
+/* { dg-warning "trigraph" "" { target *-*-* } 6 } */
index c50f73cc1d508a00e19e3eac5d23aec04365cc57..6217c6c06dd1e9053443e2f9c0043d53db6a6539 100644 (file)
@@ -1,3 +1,12 @@
+2014-03-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR preprocessor/60400
+       Backport from mainline
+       2013-06-24  Dehao Chen  <dehao@google.com>
+
+       * files.c (_cpp_stack_include): Fix the highest_location when header
+       file is guarded by #ifndef and is included twice.
+
 2013-10-16  Release Manager
 
        * GCC 4.8.2 released.
index 5c5a0b9b5146e4ff171e133885cb158a17c9ba02..ea91b02047da4c6989cdb8d1341fa008597ef3f4 100644 (file)
@@ -983,6 +983,7 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets,
 {
   struct cpp_dir *dir;
   _cpp_file *file;
+  bool stacked;
 
   dir = search_path_head (pfile, fname, angle_brackets, type);
   if (!dir)
@@ -993,19 +994,26 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets,
   if (type == IT_DEFAULT && file == NULL)
     return false;
 
-  /* Compensate for the increment in linemap_add that occurs in
-     _cpp_stack_file.  In the case of a normal #include, we're
-     currently at the start of the line *following* the #include.  A
-     separate source_location for this location makes no sense (until
-     we do the LC_LEAVE), and complicates LAST_SOURCE_LINE_LOCATION.
-     This does not apply if we found a PCH file (in which case
-     linemap_add is not called) or we were included from the
-     command-line.  */
+  /* Compensate for the increment in linemap_add that occurs if
+      _cpp_stack_file actually stacks the file.  In the case of a
+     normal #include, we're currently at the start of the line
+     *following* the #include.  A separate source_location for this
+     location makes no sense (until we do the LC_LEAVE), and
+     complicates LAST_SOURCE_LINE_LOCATION.  This does not apply if we
+     found a PCH file (in which case linemap_add is not called) or we
+     were included from the command-line.  */
   if (file->pchname == NULL && file->err_no == 0
       && type != IT_CMDLINE && type != IT_DEFAULT)
     pfile->line_table->highest_location--;
 
-  return _cpp_stack_file (pfile, file, type == IT_IMPORT);
+  stacked = _cpp_stack_file (pfile, file, type == IT_IMPORT);
+
+  if (!stacked)
+    /* _cpp_stack_file didn't stack the file, so let's rollback the
+       compensation dance we performed above.  */
+    pfile->line_table->highest_location++;
+
+  return stacked;
 }
 
 /* Could not open FILE.  The complication is dependency output.  */