Hi! 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. I think it isn't really useful to print gigabytes for very long strings, so the patch also shrinks the string with ... at the end indicating continuation, but if you think that is undesirable, I can leave it out (though, at least theoretically, while STRING_CSTs can't be longer than 2GB because tree_string has int length, CONST_STRING is just a pointer without length and thus on 64-bit hosts could be longer, so if not capping at 1K, I think we need to cap at 2GB-1 or 4GB-1 (pretty_print_string takes unsigned nbytes). Or of course we can change it to size_t nbytes.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2020-03-05 Jakub Jelinek <ja...@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. * 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/tree-pretty-print.h.jj 2020-01-12 11:54:38.499381937 +0100 +++ gcc/tree-pretty-print.h 2020-03-04 14:50:22.737021195 +0100 @@ -47,6 +47,7 @@ extern void print_declaration (pretty_pr 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 *, unsigned); 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); --- gcc/tree-pretty-print.c.jj 2020-01-30 17:55:50.411163667 +0100 +++ gcc/tree-pretty-print.c 2020-03-04 14:49:53.673451945 +0100 @@ -45,7 +45,6 @@ along with GCC; see the file COPYING3. /* 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,7 +4215,7 @@ print_call_name (pretty_printer *pp, tre /* Print the first N characters in the array STR, replacing non-printable characters (including embedded nuls) with unambiguous escape sequences. */ -static void +void pretty_print_string (pretty_printer *pp, const char *str, unsigned n) { if (str == NULL) --- gcc/print-rtl.c.jj 2020-01-12 11:54:36.915405835 +0100 +++ gcc/print-rtl.c 2020-03-04 14:55:55.089094999 +0100 @@ -1685,7 +1685,15 @@ print_value (pretty_printer *pp, const_r pp_string (pp, tmp); break; case CONST_STRING: - pp_printf (pp, "\"%s\"", XSTR (x, 0)); + pp_string (pp, "\""); + if (size_t nbytes = strlen (XSTR (x, 0))) + { + unsigned int n = MIN (nbytes, 1024); + pretty_print_string (pp, XSTR (x, 0), n); + if (n != nbytes) + pp_string (pp, "..."); + } + pp_string (pp, "\""); break; case SYMBOL_REF: pp_printf (pp, "`%s'", XSTR (x, 0)); --- gcc/testsuite/gcc.dg/pr93399.c.jj 2020-03-04 15:20:01.281631147 +0100 +++ gcc/testsuite/gcc.dg/pr93399.c 2020-03-04 15:19:18.426266715 +0100 @@ -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; +} Jakub