+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>
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>
* gfortran.dg/max_fmax_aarch64.f90: Rename to...
--- /dev/null
+/* 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" } } */
return 0;
}
-/* { dg-final { scan-tree-dump "string_0 = \"\";" "optimized" } } */
-/* { dg-final { scan-tree-dump "string_4 = \"\\\\4\";" "optimized" } } */
+/* { dg-final { scan-tree-dump "string_0 = \"\\\\x00\";" "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_51 = \"3\";" "optimized" } } */
/* { dg-final { scan-tree-dump "string_255 = \"\\\\xff\";" "optimized" } } */
/* 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);
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:
{
}
}
-/* 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])
{
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++;
}
}