re PR c/66415 (ice in location_column_from_byte_offset)
authorMarek Polacek <polacek@redhat.com>
Mon, 8 Jun 2015 15:16:12 +0000 (15:16 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Mon, 8 Jun 2015 15:16:12 +0000 (15:16 +0000)
PR c/66415
* c-format.c (location_from_offset): Return LOC if LINE is null.

* line-map.c (linemap_position_for_loc_and_offset): Remove
linemap_assert_fails; reverse conditions.

* gcc.dg/cpp/pr66415-1.c: New test.
* gcc.dg/cpp/pr66415-2.c: New test.

From-SVN: r224236

gcc/c-family/ChangeLog
gcc/c-family/c-format.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/pr66415-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/pr66415-2.c [new file with mode: 0644]
libcpp/ChangeLog
libcpp/line-map.c

index 6de6af54e07aa4886ad12c5e6ec67b6c60d4ba34..17816a3b73d8079656a0e70ffdb88d32ccf1bc1a 100644 (file)
@@ -1,3 +1,8 @@
+2015-06-08  Marek Polacek  <polacek@redhat.com>
+
+       PR c/66415
+       * c-format.c (location_from_offset): Return LOC if LINE is null.
+
 2015-06-05  Aldy Hernandez  <aldyh@redhat.com>
 
        * c-common.h (c_parse_final_cleanups): New prototype.
index 719b3a921cfea5a349d7dd1e3ef75549d8dee780..564e47bf0fa27570a90d9d9bdaa56401e692b7e5 100644 (file)
@@ -138,9 +138,11 @@ location_from_offset (location_t loc, int offset)
   expanded_location s = expand_location_to_spelling_point (loc);
   int line_width;
   const char *line = location_get_source_line (s, &line_width);
+  if (line == NULL)
+    return loc;
   line += s.column - 1 ;
   line_width -= s.column - 1;
-  unsigned int column = 
+  unsigned int column =
     location_column_from_byte_offset (line, line_width, (unsigned) offset);
 
   return linemap_position_for_loc_and_offset (line_table, loc, column);
index 5537a46346c90839a8599d77b440ce3c7fd739d0..202551f2161250596557278420b8b8e5999a235a 100644 (file)
@@ -1,3 +1,9 @@
+2015-06-08  Marek Polacek  <polacek@redhat.com>
+
+       PR c/66415
+       * gcc.dg/cpp/pr66415-1.c: New test.
+       * gcc.dg/cpp/pr66415-2.c: New test.
+
 2015-06-08  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/66422
diff --git a/gcc/testsuite/gcc.dg/cpp/pr66415-1.c b/gcc/testsuite/gcc.dg/cpp/pr66415-1.c
new file mode 100644 (file)
index 0000000..922e326
--- /dev/null
@@ -0,0 +1,9 @@
+/* PR c/66415 */
+/* { dg-do compile } */
+/* { dg-options "-Wformat" } */
+
+void
+fn1 (void)
+{
+  __builtin_printf                                ("xxxxxxxxxxxxxxxxx%dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); /* { dg-warning "format" } */
+}
diff --git a/gcc/testsuite/gcc.dg/cpp/pr66415-2.c b/gcc/testsuite/gcc.dg/cpp/pr66415-2.c
new file mode 100644 (file)
index 0000000..c168ce9
--- /dev/null
@@ -0,0 +1,11 @@
+/* PR c/66415 */
+/* { dg-do compile } */
+/* { dg-options "-Wformat" } */
+
+#24
+void
+fn1 (void)
+{
+  __builtin_printf                                ("xxxxxxxxxxxxxxxxx%dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
+  /* { dg-warning "format" "" { target *-*-* } 27 } */
+}
index 31d3b6102843060eb3b11d41de6a9d0f93edd2aa..f373dad5130d0514d32d57bb13ff3973e77fc0e3 100644 (file)
@@ -1,3 +1,9 @@
+2015-06-08  Marek Polacek  <polacek@redhat.com>
+
+       PR c/66415
+       * line-map.c (linemap_position_for_loc_and_offset): Remove
+       linemap_assert_fails; reverse conditions.
+
 2015-05-26  Manuel López-Ibáñez  <manu@gcc.gnu.org>
 
        * line-map.c (LINE_MAP_MAX_COLUMN_NUMBER
index 972f66cb90bc3c4d1c8f3cd45f9ee16e724b80ce..d58cad23fdbf440273ed346bd5ef7d56d70d52ef 100644 (file)
@@ -688,15 +688,17 @@ linemap_position_for_loc_and_offset (struct line_maps *set,
   /* We find the real location and shift it.  */
   loc = linemap_resolve_location (set, loc, LRK_SPELLING_LOCATION, &map);
   /* The new location (loc + offset) should be higher than the first
-     location encoded by MAP.  */
-  if (linemap_assert_fails (MAP_START_LOCATION (map) < loc + offset))
+     location encoded by MAP.
+     FIXME: We used to linemap_assert_fails here and in the if below,
+     but that led to PR66415.  So give up for now.  */
+  if ((MAP_START_LOCATION (map) >= loc + offset))
     return loc;
 
   /* If MAP is not the last line map of its set, then the new location
      (loc + offset) should be less than the first location encoded by
      the next line map of the set.  */
   if (map != LINEMAPS_LAST_ORDINARY_MAP (set))
-    if (linemap_assert_fails (loc + offset < MAP_START_LOCATION (&map[1])))
+    if ((loc + offset >= MAP_START_LOCATION (&map[1])))
       return loc;
 
   offset += SOURCE_COLUMN (map, loc);