diff options
author | Martin Sebor <msebor@redhat.com> | 2018-08-22 16:42:56 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2018-08-22 10:42:56 -0600 |
commit | b56b07639b1bd36383a0763ba80260c4858160ed (patch) | |
tree | e9e49026149911c53095b13a18db88691d0aaa24 /gcc/tree-pretty-print.c | |
parent | ecc643a81e7f7571970b196c237e524a7d99b9b4 (diff) | |
download | gcc-b56b07639b1bd36383a0763ba80260c4858160ed.zip gcc-b56b07639b1bd36383a0763ba80260c4858160ed.tar.gz gcc-b56b07639b1bd36383a0763ba80260c4858160ed.tar.bz2 |
PR middle-end/87052 - STRING_CST printing incomplete in Gimple dumps
gcc/testsuite/ChangeLog:
PR middle-end/87052
* gcc.dg/pr87052.c: New test.
* gcc.dg/tree-ssa/dump-3.c: Adjust.
gcc/ChangeLog:
PR middle-end/87052
* tree-pretty-print.c (pretty_print_string): Add argument.
(dump_generic_node): Call to pretty_print_string with string size.
From-SVN: r263781
Diffstat (limited to 'gcc/tree-pretty-print.c')
-rw-r--r-- | gcc/tree-pretty-print.c | 68 |
1 files changed, 22 insertions, 46 deletions
diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c index 627d8d7..6221427 100644 --- a/gcc/tree-pretty-print.c +++ b/gcc/tree-pretty-print.c @@ -37,7 +37,7 @@ 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 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); @@ -1800,10 +1800,13 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags, break; case STRING_CST: - pp_string (pp, "\""); - pretty_print_string (pp, TREE_STRING_POINTER (node)); - pp_string (pp, "\""); - break; + { + pp_string (pp, "\""); + if (unsigned nbytes = TREE_STRING_LENGTH (node)) + pretty_print_string (pp, TREE_STRING_POINTER (node), nbytes); + pp_string (pp, "\""); + break; + } case VECTOR_CST: { @@ -3865,15 +3868,16 @@ 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', ... */ +/* 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) +pretty_print_string (pretty_printer *pp, const char *str, unsigned n) { if (str == NULL) return; - while (*str) + for ( ; n; --n, ++str) { switch (str[0]) { @@ -3913,48 +3917,20 @@ pretty_print_string (pretty_printer *pp, const char *str) pp_string (pp, "\\'"); break; - /* No need to handle \0; the loop terminates on \0. */ - - case '\1': - pp_string (pp, "\\1"); - break; - - case '\2': - pp_string (pp, "\\2"); - break; - - case '\3': - pp_string (pp, "\\3"); - break; - - case '\4': - pp_string (pp, "\\4"); - break; - - case '\5': - pp_string (pp, "\\5"); - break; - - case '\6': - pp_string (pp, "\\6"); - break; - - case '\7': - pp_string (pp, "\\7"); - break; - default: - if (!ISPRINT (str[0])) + if (str[0] || n > 1) { - char buf[5]; - sprintf (buf, "\\x%x", (unsigned char)str[0]); - pp_string (pp, buf); + if (!ISPRINT (str[0])) + { + char buf[5]; + sprintf (buf, "\\x%02x", (unsigned char)str[0]); + pp_string (pp, buf); + } + else + pp_character (pp, str[0]); + break; } - else - pp_character (pp, str[0]); - break; } - str++; } } |