Commit b56b0763 by Martin Sebor Committed by Martin Sebor

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
parent ecc643a8
2018-08-22 Martin Sebor <msebor@redhat.com>
PR middle-end/87052
* tree-pretty-print.c (pretty_print_string): Add argument.
(dump_generic_node): Call to pretty_print_string with string size.
2018-08-22 Segher Boessenkool <segher@kernel.crashing.org> 2018-08-22 Segher Boessenkool <segher@kernel.crashing.org>
PR rtl-optimization/86771 PR rtl-optimization/86771
......
2018-08-22 Martin Sebor <msebor@redhat.com>
PR middle-end/87052
* gcc.dg/pr87052.c: New test.
* gcc.dg/tree-ssa/dump-3.c: Adjust.
2018-08-22 Szabolcs Nagy <szabolcs.nagy@arm.com> 2018-08-22 Szabolcs Nagy <szabolcs.nagy@arm.com>
* gfortran.dg/max_fmax_aarch64.f90: Rename to... * gfortran.dg/max_fmax_aarch64.f90: Rename to...
......
/* PR middle-end/87052 - STRING_CST printing incomplete in Gimple dumps
{ dg-do compile }
{ dg-options "-fdump-tree-gimple" } */
void sink (const void*, ...);
void test (void)
{
const char a[3] = "\000ab";
/* Expect the following in the dump:
a = "\x00ab"; */
const char b[] = { 'a', 0, 'b', 'c' };
/* Expect the following:
b = "a\x00bc"; */
const char c[] = "";
/* Expect the following:
c = ""; */
const char d[0] = { };
/* Expect the following:
d = ""; */
const char e[0] = "";
/* Expect nothing. */
sink (a, b, c, d, e);
}
/* { dg-final { scan-tree-dump-times "a = \"\\\\x00ab\";" 1 "gimple" } }
{ dg-final { scan-tree-dump-times "b = \"a\\\\x00bc\";" 1 "gimple" } }
{ dg-final { scan-tree-dump-times "c = \"\";" 1 "gimple" } }
{ dg-final { scan-tree-dump-times "d = { *};" 1 "gimple" } }
{ dg-final { scan-tree-dump-times "e = " 1 "gimple" } }
{ dg-final { scan-tree-dump-times "e = {CLOBBER}" 1 "gimple" } } */
...@@ -263,8 +263,8 @@ int main() ...@@ -263,8 +263,8 @@ int main()
return 0; return 0;
} }
/* { dg-final { scan-tree-dump "string_0 = \"\";" "optimized" } } */ /* { dg-final { scan-tree-dump "string_0 = \"\\\\x00\";" "optimized" } } */
/* { dg-final { scan-tree-dump "string_4 = \"\\\\4\";" "optimized" } } */ /* { dg-final { scan-tree-dump "string_4 = \"\\\\x04\";" "optimized" } } */
/* { dg-final { scan-tree-dump "string_28 = \"\\\\x1c\";" "optimized" } } */ /* { dg-final { scan-tree-dump "string_28 = \"\\\\x1c\";" "optimized" } } */
/* { dg-final { scan-tree-dump "string_51 = \"3\";" "optimized" } } */ /* { dg-final { scan-tree-dump "string_51 = \"3\";" "optimized" } } */
/* { dg-final { scan-tree-dump "string_255 = \"\\\\xff\";" "optimized" } } */ /* { dg-final { scan-tree-dump "string_255 = \"\\\\xff\";" "optimized" } } */
......
...@@ -37,7 +37,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -37,7 +37,7 @@ along with GCC; see the file COPYING3. If not see
/* Local functions, macros and variables. */ /* Local functions, macros and variables. */
static const char *op_symbol (const_tree); 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 newline_and_indent (pretty_printer *, int);
static void maybe_init_pretty_print (FILE *); static void maybe_init_pretty_print (FILE *);
static void print_struct_decl (pretty_printer *, const_tree, int, dump_flags_t); 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, ...@@ -1800,10 +1800,13 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags,
break; break;
case STRING_CST: case STRING_CST:
pp_string (pp, "\""); {
pretty_print_string (pp, TREE_STRING_POINTER (node)); pp_string (pp, "\"");
pp_string (pp, "\""); if (unsigned nbytes = TREE_STRING_LENGTH (node))
break; pretty_print_string (pp, TREE_STRING_POINTER (node), nbytes);
pp_string (pp, "\"");
break;
}
case VECTOR_CST: case VECTOR_CST:
{ {
...@@ -3865,15 +3868,16 @@ print_call_name (pretty_printer *pp, tree node, dump_flags_t flags) ...@@ -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 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) if (str == NULL)
return; return;
while (*str) for ( ; n; --n, ++str)
{ {
switch (str[0]) switch (str[0])
{ {
...@@ -3913,48 +3917,20 @@ pretty_print_string (pretty_printer *pp, const char *str) ...@@ -3913,48 +3917,20 @@ pretty_print_string (pretty_printer *pp, const char *str)
pp_string (pp, "\\'"); pp_string (pp, "\\'");
break; 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: default:
if (!ISPRINT (str[0])) if (str[0] || n > 1)
{ {
char buf[5]; if (!ISPRINT (str[0]))
sprintf (buf, "\\x%x", (unsigned char)str[0]); {
pp_string (pp, buf); 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++;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment