]> gcc.gnu.org Git - gcc.git/commitdiff
PR preprocessor/83173: Additional check before decrementing highest_location
authorMike Gulick <mgulick@mathworks.com>
Tue, 27 Nov 2018 15:49:43 +0000 (15:49 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Tue, 27 Nov 2018 15:49:43 +0000 (15:49 +0000)
2018-11-27  Mike Gulick  <mgulick@mathworks.com>

PR preprocessor/83173
* files.c (_cpp_stack_include): Check if
line_table->highest_location is past current line before
decrementing.

From-SVN: r266516

libcpp/ChangeLog
libcpp/files.c

index 575f18e5e0cb6b90e69b3bbeb9900457bf101b47..71fc213433a3956f8d851396e580c15445591448 100644 (file)
@@ -1,3 +1,10 @@
+2018-11-27  Mike Gulick  <mgulick@mathworks.com>
+
+       PR preprocessor/83173
+       * files.c (_cpp_stack_include): Check if
+       line_table->highest_location is past current line before
+       decrementing.
+
 2018-11-13  David Malcolm  <dmalcolm@redhat.com>
 
        * charset.c: Replace "source_location" with "location_t".
index 3771fad75ec1dfb7fc3bd00361b7ea446b4b8a04..fe80e84454b3050a78062d1b392f5b7faa8a1e2e 100644 (file)
@@ -1012,6 +1012,7 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets,
   struct cpp_dir *dir;
   _cpp_file *file;
   bool stacked;
+  bool decremented = false;
 
   /* For -include command-line flags we have type == IT_CMDLINE.
      When the first -include file is processed we have the case, where
@@ -1035,20 +1036,33 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets,
     return false;
 
   /* 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 location_t 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.  */
+     _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 location_t 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.  In the case that the #include is the last
+     line in the file, highest_location still points to the current
+     line, not the start of the next line, so we do not decrement in
+     this case.  See plugin/location-overflow-test-pr83173.h for an
+     example.  */
   if (file->pchname == NULL && file->err_no == 0
       && type != IT_CMDLINE && type != IT_DEFAULT)
-    pfile->line_table->highest_location--;
+    {
+      int highest_line = linemap_get_expansion_line (pfile->line_table,
+                                                    pfile->line_table->highest_location);
+      int source_line = linemap_get_expansion_line (pfile->line_table, loc);
+      if (highest_line > source_line)
+       {
+         pfile->line_table->highest_location--;
+         decremented = true;
+       }
+    }
 
   stacked = _cpp_stack_file (pfile, file, type == IT_IMPORT, loc);
 
-  if (!stacked)
+  if (decremented && !stacked)
     /* _cpp_stack_file didn't stack the file, so let's rollback the
        compensation dance we performed above.  */
     pfile->line_table->highest_location++;
This page took 0.07198 seconds and 5 git commands to generate.