]> gcc.gnu.org Git - gcc.git/commitdiff
Prevent ICEs due to bogus substring locations (PR preprocessor/79210)
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 31 Jan 2017 20:22:43 +0000 (20:22 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Tue, 31 Jan 2017 20:22:43 +0000 (20:22 +0000)
gcc/ChangeLog:
PR preprocessor/79210
* input.c (get_substring_ranges_for_loc): Replace line_width
assertion with error-handling.

gcc/testsuite/ChangeLog:
PR preprocessor/79210
* gcc.dg/format/pr79210.c: New test case.
* gcc.dg/plugin/diagnostic-test-string-literals-2.c (test_pr79210):
New function.

From-SVN: r245070

gcc/ChangeLog
gcc/input.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/format/pr79210.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-2.c

index 6f8d86085ef2687975b08cefe9ad2b802e4fb54c..a264140a3f9e0e706e66290d67acbf3f27046880 100644 (file)
@@ -1,3 +1,9 @@
+2017-01-31  David Malcolm  <dmalcolm@redhat.com>
+
+       PR preprocessor/79210
+       * input.c (get_substring_ranges_for_loc): Replace line_width
+       assertion with error-handling.
+
 2017-01-31  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/77318
index 3e67314932a1faf08a7db2fb59fc119bb2a913f2..38deb62db216f9f5c52248525ee18e1f0c32c2fa 100644 (file)
@@ -1395,7 +1395,10 @@ get_substring_ranges_for_loc (cpp_reader *pfile,
       const char *literal = line + start.column - 1;
       int literal_length = finish.column - start.column + 1;
 
-      gcc_assert (line_width >= (start.column - 1 + literal_length));
+      /* Ensure that we don't crash if we got the wrong location.  */
+      if (line_width < (start.column - 1 + literal_length))
+       return "line is not wide enough";
+
       cpp_string from;
       from.len = literal_length;
       /* Make a copy of the literal, to avoid having to rely on
index 302843ddcdd7e5676b4025644423fb491a1ce1fe..f7cf0f489a2e0cab16ebb3b7765ea292494066ea 100644 (file)
@@ -1,3 +1,10 @@
+2017-01-31  David Malcolm  <dmalcolm@redhat.com>
+
+       PR preprocessor/79210
+       * gcc.dg/format/pr79210.c: New test case.
+       * gcc.dg/plugin/diagnostic-test-string-literals-2.c (test_pr79210):
+       New function.
+
 2017-01-31  Nathan Sidwell  <nathan@acm.org>
 
        PR c++/79290
diff --git a/gcc/testsuite/gcc.dg/format/pr79210.c b/gcc/testsuite/gcc.dg/format/pr79210.c
new file mode 100644 (file)
index 0000000..71f5dd6
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-Wformat -Wformat-signedness" } */
+
+__attribute__((format(printf, 3, 4)))
+void dev_printk(const char *level, void *dev, const char *fmt, ...);
+
+#define lpfc_vport_param_init(attr)    \
+void lpfc_##attr##_init(void *vport, unsigned int val) \
+{ \
+       dev_printk("3", (void *)0, \
+                  "0423 lpfc_"#attr" attribute cannot be set to %d, "\
+                  "allowed range is [0, 1]\n", val); \
+}
+
+#define LPFC_VPORT_ATTR_R(name, desc) \
+unsigned int lpfc_##name;\
+lpfc_vport_param_init(name)\
+
+LPFC_VPORT_ATTR_R(peer_port_login,
+                 "Allow peer ports on the same physical port to login to each "
+                 "other.");
+
+/* { dg-warning "6: format .%d. expects argument of type .int., but argument 4 has type .unsigned int. " "" { target *-*-* } .-12 } */
index 25cb3f055d33f0332586744e73a612b9d5c9952a..e916b93bb5df528a00b04f634d6b2e97bc3c3205 100644 (file)
@@ -51,3 +51,26 @@ test_stringified_token_3 (int x)
 #undef FOO
 }
 
+/* Test of a stringified macro argument within a concatenation.  */
+
+void
+test_pr79210 (void)
+{
+#define lpfc_vport_param_init(attr)    \
+       __emit_string_literal_range ( \
+                  "0423 lpfc_"#attr" attribute cannot be set to %d, "\
+                  "allowed range is [0, 1]\n", 54, 53, 54) \
+
+#define LPFC_VPORT_ATTR_R(name, decc)          \
+  unsigned int lpfc_##name;                    \
+  lpfc_vport_param_init(name) \
+
+  LPFC_VPORT_ATTR_R(peer_port_login,
+  "some multiline blurb with a short final line "
+  "here");
+
+  /* { dg-error "19: unable to read substring location: line is not wide enough" "" { target *-*-* } .-11 } */
+
+#undef LPFC_VPORT_ATTR_R
+#undef lpfc_vport_param_init
+}
This page took 0.089303 seconds and 5 git commands to generate.