This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, trivial, 3/3, PR70433] Handle backslash in pp_write_text_as_dot_label_to_stream


Hi,

this patch fixes PR70433.

Consider test.c:
...
#include <stdio.h>

void
test (void)
{
  printf ("\"%s\"",__FUNCTION__);
}
...

In the dump file we find the backslashes in the string:
...
  printf ("\"%s\"", &__FUNCTION__);
...

But the dot file contains:
...
printf\ (\"\\"%s\\"\",\ &__FUNCTION__);
...

Which translates to this string in the pdf file, without the backslashes:
...
printf (""%s"", &__FUNCTION__);
...

The patch classifies the backslash as always-escape in pp_write_text_as_dot_label_to_stream, and that fixes the PR. [ Also, the patch adds an assert to prevent running into a known graphiz PR related to backslashes. ]

Bootstrapped and reg-tested on x86_64.

Will commit to stage1 trunk as trivial.

[ I'd add a testcase, but that is blocked on the lib/scandump.exp/dump-suffix bit of https://gcc.gnu.org/ml/gcc-patches/2016-03/msg01077.html which is awaiting review. ]

Thanks,
- Tom
Handle backslash in pp_write_text_as_dot_label_to_stream

2016-04-04  Tom de Vries  <tom@codesourcery.com>

	PR other/70433
	* pretty-print.c (pp_write_text_as_dot_label_to_stream): Escape
	backslash in label.

---
 gcc/pretty-print.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c
index c3a90a7..8ac3d34 100644
--- a/gcc/pretty-print.c
+++ b/gcc/pretty-print.c
@@ -182,6 +182,12 @@ pp_write_text_as_dot_label_to_stream (pretty_printer *pp, bool for_record)
 
 	/* The following characters always have to be escaped
 	   for use in labels.  */
+	case '\\':
+	  /* There is a bug in some (f.i. 2.36.0) versions of graphiz
+	     ( http://www.graphviz.org/mantisbt/view.php?id=2524 ) related to
+	     backslash as last char in label.  Let's avoid triggering it.  */
+	  gcc_assert (*(p + 1) != '\0');
+	  /* Fall through.  */
 	case '"':
 	  escape_char = true;
 	  break;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]