]> 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>
Thu, 5 Mar 2020 08:12:44 +0000 (09:12 +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 897c5986e8d5fe60a434a07f156c01f9025f248f..db58bbe662e3cb64f7fa3293065d3bf892092888 100644 (file)
@@ -1,3 +1,13 @@
+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-05  Richard Biener  <rguenther@suse.de>
            Jakub Jelinek  <jakub@redhat.com>
 
index 653e9c6c7808a86e3ffa132d621b95eb4278c090..611ea079c371d56540ed1d2d1616c126641a7e54 100644 (file)
@@ -1685,7 +1685,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 d4e7a3ac690b86cf69c5a682753037a6e1d15d33..5b94ab519a0a914d824a5f74024a3102281251a9 100644 (file)
@@ -1,5 +1,8 @@
 2020-03-05  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/93399
+       * gcc.dg/pr93399.c: New test.
+
        PR tree-optimization/93582
        * gcc.dg/tree-ssa/pr93582-11.c: New test.
 
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 7de8c7b0cb723c8abcfd7ba49ab4176175fa8f32..885ca8cd32951de6e619c9aa716a0c372b15a0b5 100644 (file)
@@ -45,7 +45,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);
@@ -4216,8 +4215,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 49b04d4c86ce5e40f719e92c0b038eee6a946bbf..33a2d4031695e8f20bd50380dcde42bf3e4dbd8b 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);