public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r8-10458] print-rtl: Fix printing of CONST_STRING in DEBUG_INSNs [PR93399]
@ 2020-09-17 14:24 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-09-17 14:24 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:c035257d1f775f44359fe55ceb3d018a68d87114

commit r8-10458-gc035257d1f775f44359fe55ceb3d018a68d87114
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Mar 5 09:12:44 2020 +0100

    print-rtl: Fix printing of CONST_STRING in DEBUG_INSNs [PR93399]
    
    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.
    
    (cherry picked from commit e0d6777cda966b04fc47d544c09839c4fa94343c)

Diff:
---
 gcc/print-rtl.c                |  4 +++-
 gcc/testsuite/gcc.dg/pr93399.c | 17 +++++++++++++++++
 gcc/tree-pretty-print.c        |  3 +--
 gcc/tree-pretty-print.h        |  1 +
 4 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/gcc/print-rtl.c b/gcc/print-rtl.c
index 37c0d53fae2..69ca73c3a6d 100644
--- a/gcc/print-rtl.c
+++ b/gcc/print-rtl.c
@@ -1664,7 +1664,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));
+      pp_string (pp, "\"");
       break;
     case SYMBOL_REF:
       pp_printf (pp, "`%s'", XSTR (x, 0));
diff --git a/gcc/testsuite/gcc.dg/pr93399.c b/gcc/testsuite/gcc.dg/pr93399.c
new file mode 100644
index 00000000000..3d9299018be
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr93399.c
@@ -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;
+}
diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c
index 276ad00a7b2..9256fcb67fe 100644
--- a/gcc/tree-pretty-print.c
+++ b/gcc/tree-pretty-print.c
@@ -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*);
 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);
@@ -3842,7 +3841,7 @@ print_call_name (pretty_printer *pp, tree node, dump_flags_t flags)
 
 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ...  */
 
-static void
+void
 pretty_print_string (pretty_printer *pp, const char *str)
 {
   if (str == NULL)
diff --git a/gcc/tree-pretty-print.h b/gcc/tree-pretty-print.h
index cf2427f9d27..c452cd9b011 100644
--- a/gcc/tree-pretty-print.h
+++ b/gcc/tree-pretty-print.h
@@ -44,6 +44,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 *);
 extern void print_call_name (pretty_printer *, tree, dump_flags_t);
 extern void percent_K_format (text_info *, tree);
 extern void pp_tree_identifier (pretty_printer *, tree);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-17 14:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 14:24 [gcc r8-10458] print-rtl: Fix printing of CONST_STRING in DEBUG_INSNs [PR93399] Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).