substring locations and # line directives (PR preprocessor/78569)
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 30 Nov 2016 01:13:37 +0000 (01:13 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Wed, 30 Nov 2016 01:13:37 +0000 (01:13 +0000)
The ICE in PR preprocessor/78569 appears to be due to an attempt to
generate substring locations in a .i file where the underlying .c file
has changed since the .i file was generated.

This can't work, so it seems safest for the on-demand substring
locations to be unavailable for such files, falling back to
"whole string" locations for such cases.

gcc/ChangeLog:
PR preprocessor/78569
* input.c (get_substring_ranges_for_loc): Fail gracefully if
line directives were present.

gcc/testsuite/ChangeLog:
PR preprocessor/78569
* gcc.dg/format/pr78569.c: New test case.

From-SVN: r242990

gcc/ChangeLog
gcc/input.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/format/pr78569.c [new file with mode: 0644]

index 6c37db0f22da4fd5bebb8c8617904a807c6cc3fa..2af1d979dcff8310281183e6583d0968b0401cef 100644 (file)
@@ -1,3 +1,9 @@
+2016-11-29  David Malcolm  <dmalcolm@redhat.com>
+
+       PR preprocessor/78569
+       * input.c (get_substring_ranges_for_loc): Fail gracefully if
+       line directives were present.
+
 2016-11-30  Matthias Klose  <doko@ubuntu.com>
 
        * doc/install.texi: Document configure options --enable-objc-gc
index 611e18b541ecbd3d200e64e5f3eee520694ecd95..1c7228a00806d43a7af1b35300334906e81d40be 100644 (file)
@@ -1331,6 +1331,16 @@ get_substring_ranges_for_loc (cpp_reader *pfile,
   if (cpp_get_options (pfile)->track_macro_expansion != 2)
     return "track_macro_expansion != 2";
 
+  /* If #line or # 44 "file"-style directives are present, then there's
+     no guarantee that the line numbers we have can be used to locate
+     the strings.  For example, we might have a .i file with # directives
+     pointing back to lines within a .c file, but the .c file might
+     have been edited since the .i file was created.
+     In such a case, the safest course is to disable on-demand substring
+     locations.  */
+  if (line_table->seen_line_directive)
+    return "seen line directive";
+
   /* If string concatenation has occurred at STRLOC, get the locations
      of all of the literal tokens making up the compound string.
      Otherwise, just use STRLOC.  */
index f548855d2e15cd4aa0ca58a7e8fee72783858bd9..aeac71a5847bcafb2fb88a151284a11bff147d47 100644 (file)
@@ -1,3 +1,8 @@
+2016-11-29  David Malcolm  <dmalcolm@redhat.com>
+
+       PR preprocessor/78569
+       * gcc.dg/format/pr78569.c: New test case.
+
 2016-11-29  Martin Sebor  <msebor@redhat.com>
 
        avoid false positives on ILP32 targets.
diff --git a/gcc/testsuite/gcc.dg/format/pr78569.c b/gcc/testsuite/gcc.dg/format/pr78569.c
new file mode 100644 (file)
index 0000000..e827087
--- /dev/null
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-Wformat-length" } */
+
+/* A run of blank lines, so that we would fail the assertion in input.c:1388:
+   gcc_assert (line_width >= (start.column - 1 + literal_length));  */
+
+
+
+
+
+void test (void)
+{
+  char tmp[128];
+  /* Point to the run of blank lines, so that the components of the overlong
+     string appear to be present within the run of blank lines.  */
+# 6 "../../../../src/gcc/testsuite/gcc.dg/format/pr78569.c"
+  __builtin_snprintf (tmp, sizeof(tmp),
+                     "The Base Band sends this value as a response to a "
+                     "request for IMSI detach sent over the control "
+                     "channel uplink (see section 7.6.1).");
+
+  /* { dg-warning "output truncated" "" { target *-*-* } 7 } */
+  /* { dg-message "format output" "" { target *-*-* } 6 } */
+}