]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
print-rtl: Fix printing of CONST_STRING in DEBUG_INSNs [PR93399]
authorJakub Jelinek <jakub@redhat.com>
Thu, 5 Mar 2020 08:12:44 +0000 (09:12 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 17 Mar 2020 17:04:43 +0000 (18:04 +0100)
The following testcase fails to assemble, as CONST_STRING in the DEBUG_INSNs
is printed as is, so if it contains \n and/or \r, we are in trouble:
        .loc 1 14 3
        # DEBUG haystack => [si]
        # DEBUG needle => "
"
In the gimple dumps we print those (STRING_CSTs) as
  # DEBUG haystack => D#1
  # DEBUG needle => "\n"
so this patch uses what we use in tree printing for the CONST_STRINGs too.

2020-03-05  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/93399
* tree-pretty-print.h (pretty_print_string): Declare.
* tree-pretty-print.c (pretty_print_string): Remove forward
declaration, no longer static.  Change nbytes parameter type
from unsigned to size_t.
* print-rtl.c (print_value) <case CONST_STRING>: Use
pretty_print_string and for shrink way too long strings.

* gcc.dg/pr93399.c: New test.

gcc/ChangeLog
gcc/print-rtl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr93399.c [new file with mode: 0644]
gcc/tree-pretty-print.c
gcc/tree-pretty-print.h

index 4b81a55064af040c0398c83ba740b3702a676e05..4f8c90529016a2317cb18eb9b81b5967ae1f08e8 100644 (file)
@@ -1,6 +1,16 @@
 2020-03-17  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2020-03-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/93399
+       * tree-pretty-print.h (pretty_print_string): Declare.
+       * tree-pretty-print.c (pretty_print_string): Remove forward
+       declaration, no longer static.  Change nbytes parameter type
+       from unsigned to size_t.
+       * print-rtl.c (print_value) <case CONST_STRING>: Use
+       pretty_print_string and for shrink way too long strings.
+
        2020-03-04  Jakub Jelinek  <jakub@redhat.com>
 
        PR debug/93888
index fbb108568b3f899c10ce9b7fe12486d0751258d3..819b8473d9d8b6dbf3f944f8bab40a4fcd315c15 100644 (file)
@@ -1678,7 +1678,9 @@ print_value (pretty_printer *pp, const_rtx x, int verbose)
       pp_string (pp, tmp);
       break;
     case CONST_STRING:
-      pp_printf (pp, "\"%s\"", XSTR (x, 0));
+      pp_string (pp, "\"");
+      pretty_print_string (pp, XSTR (x, 0), strlen (XSTR (x, 0)));
+      pp_string (pp, "\"");
       break;
     case SYMBOL_REF:
       pp_printf (pp, "`%s'", XSTR (x, 0));
index edce0bec2bb6922011f191d1ab7c6859d64abcbd..7ed5402e465e6ff8c49d17116ef02b5cdac9ec7f 100644 (file)
@@ -1,6 +1,11 @@
 2020-03-17  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2020-03-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/93399
+       * gcc.dg/pr93399.c: New test.
+
        2020-03-04  Jakub Jelinek  <jakub@redhat.com>
 
        PR debug/93888
diff --git a/gcc/testsuite/gcc.dg/pr93399.c b/gcc/testsuite/gcc.dg/pr93399.c
new file mode 100644 (file)
index 0000000..3d92990
--- /dev/null
@@ -0,0 +1,17 @@
+/* PR middle-end/93399 */
+/* { dg-do assemble } */
+/* { dg-options "-fverbose-asm -dA -g -O3" } */
+
+extern inline __attribute__ ((__always_inline__, __gnu_inline__)) char *
+strstr (const char *haystack, const char *needle)
+{
+  return __builtin_strstr (haystack, needle);
+}
+
+int
+main (int argc, const char **argv)
+{
+  char *substr = strstr (argv[0], "\n");
+  char *another = strstr (argv[0], "\r\n");
+  return 0;
+}
index ae0a6c120723986dc3083f694f7560c436c0ecc5..b06b595d151ae879ddab96d7605cc9be524f155f 100644 (file)
@@ -37,7 +37,6 @@ along with GCC; see the file COPYING3.  If not see
 
 /* Local functions, macros and variables.  */
 static const char *op_symbol (const_tree);
-static void pretty_print_string (pretty_printer *, const char*, unsigned);
 static void newline_and_indent (pretty_printer *, int);
 static void maybe_init_pretty_print (FILE *);
 static void print_struct_decl (pretty_printer *, const_tree, int, dump_flags_t);
@@ -4021,8 +4020,8 @@ print_call_name (pretty_printer *pp, tree node, dump_flags_t flags)
 /* Print the first N characters in the array STR, replacing non-printable
    characters (including embedded nuls) with unambiguous escape sequences.  */
 
-static void
-pretty_print_string (pretty_printer *pp, const char *str, unsigned n)
+void
+pretty_print_string (pretty_printer *pp, const char *str, size_t n)
 {
   if (str == NULL)
     return;
index 9f59328966691efcf91aaf98610c412b23a7cbec..41697e779945b51a7036669c69feb3f3c9e4ab90 100644 (file)
@@ -47,6 +47,7 @@ extern void print_declaration (pretty_printer *, tree, int, dump_flags_t);
 extern int op_code_prio (enum tree_code);
 extern int op_prio (const_tree);
 extern const char *op_symbol_code (enum tree_code);
+extern void pretty_print_string (pretty_printer *, const char *, size_t);
 extern void print_call_name (pretty_printer *, tree, dump_flags_t);
 extern void percent_K_format (text_info *, location_t, tree);
 extern void pp_tree_identifier (pretty_printer *, tree);